added selected-any? helper operation
This commit is contained in:
parent
e76363c532
commit
6580f4df4b
3 changed files with 19 additions and 0 deletions
|
|
@ -96,6 +96,14 @@
|
|||
[path structure]
|
||||
(compiled-select-any (i/comp-paths* path) structure))
|
||||
|
||||
(def ^{:doc "Version of selected-any? that takes in a path pre-compiled with comp-paths"}
|
||||
compiled-selected-any? i/compiled-selected-any?*)
|
||||
|
||||
(defn selected-any?*
|
||||
"Returns true if any element was selected, false otherwise."
|
||||
[path structure]
|
||||
(compiled-selected-any? (i/comp-paths* path) structure))
|
||||
|
||||
;; Transformation functions
|
||||
|
||||
(def ^{:doc "Version of transform that takes in a path pre-compiled with comp-paths"}
|
||||
|
|
|
|||
|
|
@ -665,6 +665,9 @@
|
|||
(defn compiled-select-any* [path structure]
|
||||
(compiled-traverse* path identity structure))
|
||||
|
||||
(defn compiled-selected-any?* [path structure]
|
||||
(not= NONE (compiled-select-any* path structure)))
|
||||
|
||||
(defn compiled-transform*
|
||||
[^com.rpl.specter.impl.CompiledPath path transform-fn structure]
|
||||
(let [^com.rpl.specter.impl.TransformFunctions tfns (.-transform-fns path)
|
||||
|
|
|
|||
|
|
@ -574,6 +574,14 @@
|
|||
[apath structure]
|
||||
`(i/compiled-select-any* (path ~apath) ~structure))
|
||||
|
||||
(defmacro selected-any?
|
||||
"Returns true if any element was selected, false otherwise.
|
||||
This macro will attempt to do inline factoring and caching of the path, falling
|
||||
back to compiling the path on every invocation it it's not possible to
|
||||
factor/cache the path."
|
||||
[apath structure]
|
||||
`(i/compiled-selected-any?* (path ~apath) ~structure))
|
||||
|
||||
(defmacro transform
|
||||
"Navigates to each value specified by the path and replaces it by the result of running
|
||||
the transform-fn on it.
|
||||
|
|
|
|||
Loading…
Reference in a new issue