(hint proto-map clazz mapper)Create a new hint for proto-map for use by p-> calls.
clazz must resolve to the Java protobuf class of the underlying POJO contained within proto-map.
mapper must resolve to a mapper var created via defmapper.
For example:
(p/p-> (p/hint my-map MyClass my-mapper) :field_0 field_1).
This is equivalent to writing (p/p-> my-map :field_0 :field_1), except that the
produced code will be optimized using the hint of the underlying type.
See also: with-hints
Create a new hint for `proto-map` for use by p-> calls. `clazz` must resolve to the Java protobuf class of the underlying POJO contained within `proto-map.` `mapper` must resolve to a mapper var created via `defmapper`. For example: `(p/p-> (p/hint my-map MyClass my-mapper) :field_0 field_1)`. This is equivalent to writing `(p/p-> my-map :field_0 :field_1)`, except that the produced code will be optimized using the hint of the underlying type. See also: `with-hints`
(p-> x & forms)Like -> but meant to be used where the initial expression evaluates to a proto-map. Under the hood, p-> will operate on a transient version of the proto-map and persistent! it back when done. Expressions will be pipelined as much as possible (but never reordered) such that (p-> person-proto (assoc-in [:pet :name] "patch") (assoc-in [:pet :kind] :cat)) will only generate a single instance of a pet transient map to which both operations will be applied in succession.
Like `->` but meant to be used where the initial expression evaluates to a proto-map. Under the hood, `p->` will operate on a transient version of the proto-map and `persistent!` it back when done. Expressions will be pipelined as much as possible (but never reordered) such that `(p-> person-proto (assoc-in [:pet :name] "patch") (assoc-in [:pet :kind] :cat))` will only generate a single instance of a pet transient map to which both operations will be applied in succession.
(pcond-> expr & clauses)Equivalent to cond->. See p->
Equivalent to cond->. See `p->`
(with-hints hints & body)Takes a vector of hints (see hint), and introduces a scope within which all hinted variables will be type hinted in p-> calls, then executes & returns the value of body.
For example:
(defn foo [m] (p/with-hints [(p/hint m MyClass my-mapper)] {:height (p/p-> m :height) :name (p/p-> m :name)}))
Since m is hinted in the scope, both p-> calls will use the hint to produce more performant code.
Note that with-hints only applies to p-> calls directly within body, and not recursively. Therefore, the following code will not be hinted:
` (defn get-person-name [person-proto-map] (p/p-> person-proto-map :name))
(with-hints [(p/hint my-map MyClass my-mapper)] (get-person-name my-map )) `
Takes a vector of hints (see `hint`), and introduces a scope within which all hinted variables will be type hinted in `p->` calls, then executes & returns the value of `body.`
For example:
`(defn foo [m]
(p/with-hints [(p/hint m MyClass my-mapper)]
{:height (p/p-> m :height)
:name (p/p-> m :name)}))`
Since `m` is hinted in the scope, both p-> calls will use the hint to produce more performant code.
Note that with-hints only applies to p-> calls directly within `body`, and not recursively. Therefore, the following code will not be hinted:
`
(defn get-person-name [person-proto-map]
(p/p-> person-proto-map :name))
(with-hints
[(p/hint my-map MyClass my-mapper)]
(get-person-name my-map ))
`
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 |