Updated List of Macros (markdown)

This commit is contained in:
Nathan Marz 2017-03-02 23:21:26 -05:00
parent 364e9cd54f
commit ec3d2d1fa9

View file

@ -67,9 +67,7 @@ the path using `terminal`. Error is thrown if navigation finishes at a
non-`terminal` navigator. `terminal-val` is a wrapper around `terminal` and is non-`terminal` navigator. `terminal-val` is a wrapper around `terminal` and is
the `multi-transform` equivalent of `setval`. Much more efficient than doing the the `multi-transform` equivalent of `setval`. Much more efficient than doing the
transformations with `transform` one after another when the transformations transformations with `transform` one after another when the transformations
share a lot of navigation. This macro will attempt to do inline factoring and share a lot of navigation. This macro will do inline factoring and caching of the path.
caching of the path, falling back to compiling the path on every invocation if
it's not possible to factor/cache the path.
```clojure ```clojure
(multi-transform [:a :b (multi-path [:c (terminal-val :done)] (multi-transform [:a :b (multi-path [:c (terminal-val :done)]
@ -90,9 +88,7 @@ The transform-fn in this case is expected to return `[ret user-ret]`. ret is
what's used to transform the data structure, while `user-ret` will be added to the `user-ret` sequence what's used to transform the data structure, while `user-ret` will be added to the `user-ret` sequence
in the final return. replace-in is useful for situations where you need to know the specific values in the final return. replace-in is useful for situations where you need to know the specific values
of what was transformed in the data structure. of what was transformed in the data structure.
This macro will attempt to do inline factoring and caching of the path, falling This macro will do inline factoring and caching of the path.
back to compiling the path on every invocation it it's not possible to
factor/cache the path.
Note that the `user-ret` portion of the return value of `transform-fn` must be a sequence in order to be joined onto all previous user-return values. Note that the `user-ret` portion of the return value of `transform-fn` must be a sequence in order to be joined onto all previous user-return values.
@ -113,9 +109,7 @@ Note that the `user-ret` portion of the return value of `transform-fn` must be a
`(select apath structure)` `(select apath structure)`
Navigates to and returns a sequence of all the elements specified by the path. Navigates to and returns a sequence of all the elements specified by the path.
This macro will attempt to do inline factoring and caching of the path, falling This macro will do inline factoring and caching of the path.
back to compiling the path on every invocation it it's not possible to
factor/cache the path.
```clojure ```clojure
=> (select [ALL even?] (range 10)) => (select [ALL even?] (range 10))
@ -134,9 +128,7 @@ _Added in 0.12.0_
Returns any element found or `com.rpl.specter/NONE` if nothing selected. This is the most Returns any element found or `com.rpl.specter/NONE` if nothing selected. This is the most
efficient of the various selection operations. efficient of the various selection operations.
This macro will attempt to do inline factoring and caching of the path, falling This macro will do inline factoring and caching of the path.
back to compiling the path on every invocation if it's not possible to
factor/cache the path.
```clojure ```clojure
=> (select-any STAY :a) => (select-any STAY :a)
@ -154,9 +146,7 @@ true
_Added in 0.12.0_ _Added in 0.12.0_
Returns true if any element was selected, false otherwise. Returns true if any element was selected, false otherwise.
This macro will attempt to do inline factoring and caching of the path, falling This macro will do inline factoring and caching of the path.
back to compiling the path on every invocation if it's not possible to
factor/cache the path.
```clojure ```clojure
=> (selected-any? STAY :a) => (selected-any? STAY :a)
@ -174,9 +164,7 @@ false
`(select-first apath structure)` `(select-first apath structure)`
Returns first element found. Not any more efficient than `select`, just a convenience. Returns first element found. Not any more efficient than `select`, just a convenience.
This macro will attempt to do inline factoring and caching of the path, falling This macro will do inline factoring and caching of the path.
back to compiling the path on every invocation it it's not possible to
factor/cache the path.
```clojure ```clojure
=> (select-first ALL (range 10)) => (select-first ALL (range 10))
@ -191,9 +179,7 @@ factor/cache the path.
`(select-one apath structure)` `(select-one apath structure)`
Like `select`, but returns either one element or nil. Throws exception if multiple elements found. Like `select`, but returns either one element or nil. Throws exception if multiple elements found.
This macro will attempt to do inline factoring and caching of the path, falling This macro will do inline factoring and caching of the path.
back to compiling the path on every invocation it it's not possible to
factor/cache the path.
```clojure ```clojure
;; srange returns one collection ;; srange returns one collection
@ -210,9 +196,7 @@ IllegalArgumentException More than one element found for params
`(select-one! apath structure)` `(select-one! apath structure)`
Returns exactly one element, throws exception if zero or multiple elements found. Returns exactly one element, throws exception if zero or multiple elements found.
This macro will attempt to do inline factoring and caching of the path, falling This macro will do inline factoring and caching of the path.
back to compiling the path on every invocation it it's not possible to
factor/cache the path.
```clojure ```clojure
=> (select-one! FIRST (range 5)) => (select-one! FIRST (range 5))
@ -230,9 +214,7 @@ IllegalArgumentException Expected exactly one element for params
`(setval apath aval structure)` `(setval apath aval structure)`
Navigates to each value specified by the path and replaces it by `aval`. Navigates to each value specified by the path and replaces it by `aval`.
This macro will attempt to do inline factoring and caching of the path, falling This macro will do inline factoring and caching of the path.
back to compiling the path on every invocation it it's not possible to
factor/cache the path.
```clojure ```clojure
=> (setval [ALL even?] :even (range 10)) => (setval [ALL even?] :even (range 10))
@ -245,11 +227,7 @@ factor/cache the path.
Navigates to each value specified by the path and replaces it by the result of running Navigates to each value specified by the path and replaces it by the result of running
the transform-fn on it. the transform-fn on it.
This macro will attempt to do inline factoring and caching of the path, falling This macro will do inline factoring and caching of the path.
back to compiling the path on every invocation it it's not possible to
factor/cache the path.
Note that `transform` takes as its initial arguments any collected values. Its last argument will be the structure navigated to by the passed in path.
```clojure ```clojure
=> (transform [ALL] #(* % 2) (range 10)) => (transform [ALL] #(* % 2) (range 10))
@ -271,9 +249,7 @@ _Added in 0.12.0_
Return a reducible object that traverses over `structure` to every element Return a reducible object that traverses over `structure` to every element
specified by the path. specified by the path.
This macro will attempt to do inline factoring and caching of the path, falling This macro will do inline factoring and caching of the path.
back to compiling the path on every invocation if it's not possible to
factor/cache the path.
`(reduce afn init (traverse apath structure))` will always return the same thing as `(reduce afn init (select apath structure))`, but more efficiently. The return value of `traverse` is only useful as an argument to `reduce`; for all other uses, prefer [select](#select). `(reduce afn init (traverse apath structure))` will always return the same thing as `(reduce afn init (select apath structure))`, but more efficiently. The return value of `traverse` is only useful as an argument to `reduce`; for all other uses, prefer [select](#select).