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
the `multi-transform` equivalent of `setval`. Much more efficient than doing the
transformations with `transform` one after another when the transformations
share a lot of navigation. This macro will attempt to do inline factoring and
caching of the path, falling back to compiling the path on every invocation if
it's not possible to factor/cache the path.
share a lot of navigation. This macro will do inline factoring and caching of the path.
```clojure
(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
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.
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.
This macro will do inline factoring and caching of 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.
@ -113,9 +109,7 @@ Note that the `user-ret` portion of the return value of `transform-fn` must be a
`(select apath structure)`
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
back to compiling the path on every invocation it it's not possible to
factor/cache the path.
This macro will do inline factoring and caching of the path.
```clojure
=> (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
efficient of the various selection operations.
This macro will attempt to do inline factoring and caching of the path, falling
back to compiling the path on every invocation if it's not possible to
factor/cache the path.
This macro will do inline factoring and caching of the path.
```clojure
=> (select-any STAY :a)
@ -154,9 +146,7 @@ true
_Added in 0.12.0_
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 if it's not possible to
factor/cache the path.
This macro will do inline factoring and caching of the path.
```clojure
=> (selected-any? STAY :a)
@ -174,9 +164,7 @@ false
`(select-first apath structure)`
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
back to compiling the path on every invocation it it's not possible to
factor/cache the path.
This macro will do inline factoring and caching of the path.
```clojure
=> (select-first ALL (range 10))
@ -191,9 +179,7 @@ factor/cache the path.
`(select-one apath structure)`
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
back to compiling the path on every invocation it it's not possible to
factor/cache the path.
This macro will do inline factoring and caching of the path.
```clojure
;; srange returns one collection
@ -210,9 +196,7 @@ IllegalArgumentException More than one element found for params
`(select-one! apath structure)`
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
back to compiling the path on every invocation it it's not possible to
factor/cache the path.
This macro will do inline factoring and caching of the path.
```clojure
=> (select-one! FIRST (range 5))
@ -230,9 +214,7 @@ IllegalArgumentException Expected exactly one element for params
`(setval apath aval structure)`
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
back to compiling the path on every invocation it it's not possible to
factor/cache the path.
This macro will do inline factoring and caching of the path.
```clojure
=> (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
the transform-fn on it.
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.
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.
This macro will do inline factoring and caching of the path.
```clojure
=> (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
specified by the path.
This macro will attempt to do inline factoring and caching of the path, falling
back to compiling the path on every invocation if it's not possible to
factor/cache the path.
This macro will do inline factoring and caching of 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).