Add multi-transform, terminal, and terminal-val.
This commit is contained in:
parent
c02e0ce474
commit
300f57e78a
2 changed files with 67 additions and 1 deletions
|
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
- [Core Macros](#core-macros)
|
- [Core Macros](#core-macros)
|
||||||
- [collected?](#collected)
|
- [collected?](#collected)
|
||||||
|
- [multi-transform](#multi-transform)
|
||||||
- [replace-in](#replace-in)
|
- [replace-in](#replace-in)
|
||||||
- [select](#select)
|
- [select](#select)
|
||||||
- [select-any](#select-any)
|
- [select-any](#select-any)
|
||||||
|
|
@ -62,6 +63,31 @@ to capture all the collected values as a single vector.
|
||||||
{0 "A", 1 "B", 2 "c", 3 "d", 4 "e"}
|
{0 "A", 1 "B", 2 "c", 3 "d", 4 "e"}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## multi-transform
|
||||||
|
|
||||||
|
`(multi-transform path structure)`
|
||||||
|
|
||||||
|
_Added in 0.12.0_
|
||||||
|
|
||||||
|
Just like `transform` but expects transform functions to be specified inline in
|
||||||
|
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.
|
||||||
|
|
||||||
|
```clojure
|
||||||
|
(multi-transform [:a :b (multi-path [:c (terminal-val :done)]
|
||||||
|
[:d (terminal inc)]
|
||||||
|
[:e (putval 3) (terminal +)])]
|
||||||
|
{:a {:b {:c :working :d 0 :e 1.5}}})
|
||||||
|
{:a {:b {:c :done, :d 1, :e 4.5}}}
|
||||||
|
```
|
||||||
|
|
||||||
|
See also [terminal](#List-of-Navigators#terminal) and [terminal-val](#List-of-Navigators#terminal-val).
|
||||||
|
|
||||||
## replace-in
|
## replace-in
|
||||||
|
|
||||||
`(replace-in apath transform-fn structure & args)`
|
`(replace-in apath transform-fn structure & args)`
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,4 @@
|
||||||
**Note:** Many of the descriptions and a couple of the examples are lightly edited from those found on the [Codox documentation](http://nathanmarz.github.io/specter/com.rpl.specter.html).
|
**Note:** Many of the descriptions and a couple of the examples are lightly edited from those found on the [Codox documentation](http://nathanmarz.github.io/specter/com.rpl.specter.html).
|
||||||
|
|
||||||
<!-- markdown-toc start - Don't edit this section. Run M-x markdown-toc-generate-toc again -->
|
<!-- markdown-toc start - Don't edit this section. Run M-x markdown-toc-generate-toc again -->
|
||||||
**Table of Contents**
|
**Table of Contents**
|
||||||
|
|
||||||
|
|
@ -46,6 +45,8 @@
|
||||||
- [submap](#submap)
|
- [submap](#submap)
|
||||||
- [subselect](#subselect)
|
- [subselect](#subselect)
|
||||||
- [subset](#subset)
|
- [subset](#subset)
|
||||||
|
- [terminal](#terminal)
|
||||||
|
- [terminal-val](#terminal-val)
|
||||||
- [transformed](#transformed)
|
- [transformed](#transformed)
|
||||||
- [view](#view)
|
- [view](#view)
|
||||||
- [walker](#walker)
|
- [walker](#walker)
|
||||||
|
|
@ -53,6 +54,7 @@
|
||||||
<!-- markdown-toc end -->
|
<!-- markdown-toc end -->
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Unparameterized Navigators
|
# Unparameterized Navigators
|
||||||
|
|
||||||
## ALL
|
## ALL
|
||||||
|
|
@ -752,6 +754,44 @@ new value of the subset.
|
||||||
#{:c :b :a}
|
#{:c :b :a}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## terminal
|
||||||
|
|
||||||
|
`(terminal update-fn)`
|
||||||
|
|
||||||
|
_Added in 0.12.0_
|
||||||
|
|
||||||
|
For usage with `multi-transform`, defines an endpoint in the navigation that
|
||||||
|
will have the parameterized transform function run. The transform function works
|
||||||
|
just like it does in `transform`, with collected values given as the first
|
||||||
|
arguments.
|
||||||
|
|
||||||
|
See also [terminal-val](#terminal-val) and [multi-transform](#List-of-Macros#multi-transform).
|
||||||
|
|
||||||
|
```clojure
|
||||||
|
=> (multi-transform [(putval 3) (terminal +)] 1)
|
||||||
|
4
|
||||||
|
=> (multi-transform [:a :b (multi-path [:c (terminal inc)]
|
||||||
|
[:d (putval 3) (terminal +)])]
|
||||||
|
{:a {:b {:c 42 :d 1}}})
|
||||||
|
{:a {:b {:c 43, :d 4}}}
|
||||||
|
```
|
||||||
|
|
||||||
|
## terminal-val
|
||||||
|
|
||||||
|
`(terminal-val val)`
|
||||||
|
|
||||||
|
_Added in 0.12.0_
|
||||||
|
|
||||||
|
Like `terminal` but specifies a val to set at the location regardless of
|
||||||
|
the collected values or the value at the location.
|
||||||
|
|
||||||
|
```clojure
|
||||||
|
=> (multi-transform (terminal-val 2) 3)
|
||||||
|
2
|
||||||
|
```
|
||||||
|
|
||||||
|
See also [terminal](#terminal) and [multi-transform](#List-of-Macros#multi-transform).
|
||||||
|
|
||||||
## transformed
|
## transformed
|
||||||
|
|
||||||
`(transformed path update-fn)`
|
`(transformed path update-fn)`
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue