Liking cljdoc? Tell your friends :D

fooheads.tbl

A table is vector of vectors where the first row represents the header and the rest represent the rows

A table is vector of vectors where the first row represents the header
and the rest represent the rows
raw docstring

-extract-optsclj/s

(-extract-opts tokens)

Extracts the opts from the tokens and returns [opts tokens]

Extracts the opts from the tokens and returns [opts tokens]
raw docstring

-token-or-resolveclj/s

(-token-or-resolve env token)

apply-templateclj/s

(apply-template template data)

Apply a template to (:table) data with the same shape and extract the data matching the keywords in the template. A template can represent a map and a collection of maps in one template.

A template that looks like this:

[() [Customer :order/customer] [Date :order/date] [nil nil] [Article Quantity] [* *] [:order-line/article-id :order-line/quantity]]

appled to this data:

`[() [Customer "John Doe" nil] [Date "2024-08-25" nil] [nil nil nil] [Article Desc Quantity] [103 "Bread" 1] [234 "Milk 1L" 4 [666 "BBQ Sauce" 1]]

will result in a this data structure:

`[{} {:order/customer "John Doe"} {:order/date "2024-08-25"} {} {} [{:order-line/article-id 103 :order-line/quantity "Bread"}] [{:order-line/article-id 234 :order-line/quantity "Milk 1L"}] [{:order-line/article-id 666 :order-line/quantity "BBQ Sauce"}]]

where each line in the collection part is wrapped in a vector in order to differentiate the top level values from the collection entries in further post processing into domain data.

Note that both the data and the templates can easily be created by using the tbl macro with the option {:format :table}. Example:

(tbl {:format :table} | --- | --- | | Customer | :order/customer | | Date | :order/date | | | | | Article | Quantity | | * | * | | :order-line/article-id | :order-line/quantity |)

Apply a template to (:table) data with the same shape and extract the data
matching the keywords in the template. A template can represent a map and a
collection of maps in one template.

A template that looks like this:

`[()
[Customer :order/customer]
[Date :order/date]
[nil nil]
[Article Quantity]
[* *]
[:order-line/article-id :order-line/quantity]]`

appled to this data:

`[()
[Customer "John Doe" nil]
[Date "2024-08-25" nil]
[nil nil nil]
[Article Desc Quantity]
[103 "Bread" 1]
[234 "Milk 1L" 4
[666 "BBQ Sauce" 1]]

will result in a this data structure:

`[{}
{:order/customer "John Doe"}
{:order/date "2024-08-25"}
{}
{}
[{:order-line/article-id 103 :order-line/quantity "Bread"}]
[{:order-line/article-id 234 :order-line/quantity "Milk 1L"}]
[{:order-line/article-id 666 :order-line/quantity "BBQ Sauce"}]]

where each line in the collection part is wrapped in a vector in order
to differentiate the top level values from the collection entries in further
post processing into domain data.

Note that both the data and the templates can easily be created by using
the `tbl` macro with the option `{:format :table}`. Example:

`(tbl
{:format :table}
| ---                    | ---                  |
| Customer               | :order/customer      |
| Date                   | :order/date          |
|                        |                      |
| Article                | Quantity             |
| *                      | *                    |
| :order-line/article-id | :order-line/quantity |)`
raw docstring

col-headersclj/s

(col-headers interpretation)

dataclj/s

(data interpretation)

divider-lineclj/s


interpretclj/s

(interpret table)
(interpret opts table)

Interprets the tabular data into a map with :col-headers, :row-headers, :data and :transformations.

:col-headers - a seq of column headers :row-headers - a seq of row headers :data - a vector of vectors with row values :transformations - a map with specificed tranformations to be done.

The interpretation can be configured using :

;;;;In order to interpret the table dsl, options can be ;;;;provided with a :separator and :divider. :seperator is the token ;;;;between columns and :divider is the column value in the divider ;;;;row. Default interpretation-opts are: ;;;;`{:separator '| :divider #"-{2,}"}

Interprets the tabular data into a map with :col-headers, :row-headers, :data
and :transformations.

:col-headers     - a seq of column headers
:row-headers     - a seq of row headers
:data            - a vector of vectors with row values
:transformations - a map with specificed tranformations to be done.

The interpretation can be configured using
:

;;;;In order to interpret the table dsl, options can be
;;;;provided with a :separator and :divider. :seperator is the token
;;;;between columns and :divider is the column value in the divider
;;;;row. Default interpretation-opts are:
;;;;`{:separator '| :divider #"-{2,}"}

raw docstring

make-comparatorclj/s

(make-comparator order)

nil-value?clj/s


relation->tblclj/s

(relation->tbl relation)
(relation->tbl key-order relation)

Returns a string that represents the code that created the relation. Typically used as a helper function to generate data to be used in tests.

key-order can be either a vector of keys in the order they should appear, or a map from key to position (int), or a comparator function.

Returns a string that represents the code that created the relation.
Typically used as a helper function to generate data to be used in tests.

`key-order` can be either a vector of keys in the order they should appear,
or a map from key to position (int), or a comparator function.
raw docstring

row-headersclj/s

(row-headers interpretation)

table->treeclj/s

(table->tree template rows)

Generate a tree from a template and a data table (vector of vectors).

Generate a tree from a template and a data table (vector of vectors).
raw docstring

table-formatclj/smultimethod


tabularizeclj/s

(tabularize tokens)
(tabularize opts tokens)

Interprets tokens into a 'table', a vector of vectors, using either the option :width to determine the number of columns per row, or if :width is not present, figures out the width using :divider to find a divider row.

In order to interpret the table dsl, opts can be provided with a :separator and :divider. :separator is the token between columns and :divider is the column value in the divider row.

Default opts are: {:separator '| :divider #"-{3,}"}

Takes as arguments either a seq of tokens and an opts map, or a map with :tokens and :opts (which is the output of tokenize).

Interprets tokens into a 'table', a vector of vectors, using either the option
:width to determine the number of columns per row, or if :width is not present,
figures out the width using :divider to find a divider row.

In order to interpret the table dsl, opts can be provided with a :separator
and :divider. :separator is the token between columns and :divider is the
column value in the divider row.

Default opts are: `{:separator '| :divider #"-{3,}"}`

Takes as arguments either a seq of tokens and an opts map, or a map
with :tokens and :opts (which is the output of `tokenize`).
raw docstring

tblclj/smacro

(tbl & elements)

Macro for common tables

Macro for common tables
raw docstring

template->tree-mappingclj/s

(template->tree-mapping template)
(template->tree-mapping template pk-map)

Converts a template into a tree-mapping.

Converts a template into a tree-mapping.
raw docstring

tokenizeclj/smacro

(tokenize opts & elements)

Tokenizes the elements sent in. If the first or last element is a map, that map is considered being a map of options.

tokenize itself is only interested in one option: resolve. If the resolve option is true, any symbol is trying to be resolved. If the symbol can't be resolved, it stays a symbol. This is necessary since the dividers in the table are built up with symbols.

The function returns a map with :tokens, containing all tokens (with resolved or unresolved symbols) and :opts for all options in the options map, except :resolve (since that is consumed by tokenize).

The reason for having tokenize resolving instead of (for instance) interpret is that tokenize is a macro, which means that is is in the right context to resolve whatever the user code is refering to, while a normal function is not.

Tokenizes the elements sent in. If the first or last element is a map,
that map is considered being a map of options.

`tokenize` itself is only interested in one option: resolve. If the resolve
option is true, any symbol is trying to be resolved. If the symbol can't
be resolved, it stays a symbol. This is necessary since the dividers in the
table are built up with symbols.

The function returns a map with :tokens, containing all tokens (with resolved
or unresolved symbols) and :opts for all options in the options map,
except :resolve (since that is consumed by tokenize).

The reason for having `tokenize` resolving instead of (for instance) `interpret`
is that `tokenize` is a macro, which means that is is in the right context to
resolve whatever the user code is refering to, while a normal function is not.
raw docstring

transformclj/s

(transform transformations interpretation)

Transforms an interpretation. Example:

{:col-header [:date :value :value2] :data [["2021-07-01" 10 100] ["2021-07-02" 20 200]] :opts {:coercions {:value double :date t/date :value2 str)} :ns :foo}}

opts is a map of options. Valid options are (applied in this order):

:remove-blank-lines? If true, entries with only blank values are removed.

:coercions A map of keys and functions, where the key represents the attr/column and the function is a function to apply to the values of that key.

:renames A map or renames in the same form as clojure.set/rename-keys

:ns A keyword that will be the namespace for all keys. Note, that renames are applied before ns.

:format :map - a map with {:col-header header :data data}

:maps - vector of maps with header as keys

:relation - a relation in clojure.set style

:table - a csv-like table with header as first row

opts example:

{:remove-blank-lines? true} :coercions {:date t/date} :renames {:date :from-date} :ns {:some-ns} :format :maps}

Transforms an interpretation. Example:

{:col-header [:date :value :value2]
:data [["2021-07-01" 10 100] ["2021-07-02" 20 200]]
:opts {:coercions {:value double :date t/date :value2 str)}
:ns :foo}}

opts is a map of options. Valid options are (applied in this order):

:remove-blank-lines?  If true, entries with only blank values are removed.

:coercions            A map of keys and functions, where the key represents
the attr/column and the function is a function to apply
to the values of that key.

:renames              A map or renames in the same form as
`clojure.set/rename-keys`

:ns                   A keyword that will be the namespace for all keys.
Note, that renames are applied before ns.

:format               :map - a map with {:col-header header :data data}

:maps - vector of maps with header as keys

:relation - a relation in clojure.set style

:table - a csv-like table with header as first row

opts example:

{:remove-blank-lines? true}
:coercions           {:date t/date}
:renames             {:date :from-date}
:ns                  {:some-ns}
:format              :maps}

raw docstring

transformationsclj/s

(transformations interpretation)

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close