diff --git a/List-of-Macros.md b/List-of-Macros.md index 9f83b9c..c81a3e2 100644 --- a/List-of-Macros.md +++ b/List-of-Macros.md @@ -3,6 +3,7 @@ - [Core Macros](#core-macros) - [collected?](#collected) + - [multi-transform](#multi-transform) - [replace-in](#replace-in) - [select](#select) - [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"} ``` +## 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 apath transform-fn structure & args)` diff --git a/List-of-Navigators.md b/List-of-Navigators.md index 32d06be..8f72655 100644 --- a/List-of-Navigators.md +++ b/List-of-Navigators.md @@ -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). - **Table of Contents** @@ -46,6 +45,8 @@ - [submap](#submap) - [subselect](#subselect) - [subset](#subset) + - [terminal](#terminal) + - [terminal-val](#terminal-val) - [transformed](#transformed) - [view](#view) - [walker](#walker) @@ -53,6 +54,7 @@ + # Unparameterized Navigators ## ALL @@ -752,6 +754,44 @@ new value of the subset. #{: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 path update-fn)`