Pull from data structure by using pattern.
Pattern is a DSL in clojure data structure, specify how to extract information from data.
Pull from data structure by using pattern. Pattern is a DSL in clojure data structure, specify how to extract information from data.
(context-of modifier)(context-of modifier finalizer)returns a query context of function modifier and function finalizer(default clojure.core/identity),
this could be used to:
modifier will be in the query result.modifier: returns a key-value pair which will contains in the query result. argurments are:
args: a vector that might passed to this.key-value: a key-value pair returned by original query running result.finalizer: accept a single map and returns any value which will be called when we've done querying.returns a query context of function `modifier` and function `finalizer`(default `clojure.core/identity`), this could be used to: - modify query result, the value returned by `modifier` will be in the query result. - collect information in all query results. Information on arguments: - `modifier`: returns a key-value pair which will contains in the query result. argurments are: - `args`: a vector that might passed to this. - `key-value`: a key-value pair returned by original query running result. - `finalizer`: accept a single map and returns any value which will be called when we've done querying.
(qfn pattern & body)returns an anonymous query function on pattern takes a single argument data:
Returns nil if failed to match, otherwise, all logical variables in the pattern
can be used in body. The whole query result stored in &?.
See query's documentation for syntax of the pattern.
returns an anonymous query function on `pattern` takes a single argument `data`: Returns `nil` if failed to match, otherwise, all logical variables in the pattern can be used in `body`. The whole query result stored in `&?`. See `query`'s documentation for syntax of the pattern.
(query pattern)(query pattern context)Returns a query function from pattern. A query function can be used to extract information
from data. Query function takes data as its single argument, if data matches the pattern,
returns a map of resulting data and output variable bindings, the whole matching result is in
'&? binding and other named logical variable bindings.
A pattern is a clojure data structure, in most cases, a pattern looks like the data
which it queries, for example, to query data {:a {:b {:c 5}} :d {:e 2}} to extract
:c, :e, you might use a pattern '{:a {:b {:c ?c}} :d {:e ?e}}. By marking the
information you are interested in by logic variable like ?c, ?e, or by anonymous
variable ?, you can get informatioon from the potentially massive data.
Map pattern: {...}, mimic the shape of the map to be queried
Filter pattern: If you specified a concrete value for a given key in a map, it works
like a filter, i.e., pattern {:a ? :b 1} will return an empty map on data {:a 1 :b 2}.
If you use same logical variabl in multiple places of a pattern, it has to be the
same value, so if we can not satisfy this, the matching fails. i.e.,
pattern '{:a ?x :b ?x} returns an empty map on data {:a 2 :b 3}.
Options: by enclosing a key in map pattern with a list (), and optional pairs of
options, you can process value after a match or miss. i.e., pattern
{(:a :not-found ::ok) ?} on data {:b 5} having a matching result of {:a ::ok}.
Various options supported, and can be defined by multimethod of core/apply-post.
Sequence pattern: For sequence of maps, using [] to enclose it. Sequence pattern
can have an optional variable and options. i.e., pattern
'[{:a ?} ?] on [{:a 1} {:a 3} {}] has a matching result of
[{:a 1} {:a 3} {}].
Advanced arguments. Sometimes you need subqueries sharing information among them.
context to it, which is a QueryContext instance made by
context-of function.Returns a query function from `pattern`. A query function can be used to extract information
from data. Query function takes `data` as its single argument, if data matches the pattern,
returns a map of resulting data and output variable bindings, the whole matching result is in
`'&?` binding and other named logical variable bindings.
A pattern is a clojure data structure, in most cases, a pattern looks like the data
which it queries, for example, to query data `{:a {:b {:c 5}} :d {:e 2}}` to extract
`:c`, `:e`, you might use a pattern `'{:a {:b {:c ?c}} :d {:e ?e}}`. By marking the
information you are interested in by logic variable like `?c`, `?e`, or by anonymous
variable `?`, you can get informatioon from the potentially massive data.
- Map pattern: `{...}`, mimic the shape of the map to be queried
- Filter pattern: If you specified a concrete value for a given key in a map, it works
like a filter, i.e., pattern `{:a ? :b 1}` will return an empty map on data `{:a 1 :b 2}`.
If you use same logical variabl in multiple places of a pattern, it has to be the
same value, so if we can not satisfy this, the matching fails. i.e.,
pattern `'{:a ?x :b ?x}` returns an empty map on data `{:a 2 :b 3}`.
- Options: by enclosing a key in map pattern with a list `()`, and optional pairs of
options, you can process value after a match or miss. i.e., pattern
`{(:a :not-found ::ok) ?}` on data `{:b 5}` having a matching result of `{:a ::ok}`.
Various options supported, and can be defined by multimethod of `core/apply-post`.
- Sequence pattern: For sequence of maps, using `[]` to enclose it. Sequence pattern
can have an optional variable and options. i.e., pattern
`'[{:a ?} ?]` on `[{:a 1} {:a 3} {}]` has a matching result of
`[{:a 1} {:a 3} {}]`.
Advanced arguments. Sometimes you need subqueries sharing information among them.
- You can pass an additional `context` to it, which is a `QueryContext` instance made by
`context-of` function.(run-query pattern data)(run-query f pattern data)Query data on pattern, returns a pair. See query function. Convinient for one-time use pattern.
Query `data` on `pattern`, returns a pair. See `query` function. Convinient for one-time use pattern.
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |