From 3202393cd03361dbce56df92c19fe6e758a8545a Mon Sep 17 00:00:00 2001 From: Michael Fogleman Date: Mon, 18 Sep 2017 08:35:44 -0400 Subject: [PATCH 1/5] Document 'must' multiple arguments. --- List-of-Navigators.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/List-of-Navigators.md b/List-of-Navigators.md index 678ebd1..b3456b8 100644 --- a/List-of-Navigators.md +++ b/List-of-Navigators.md @@ -715,6 +715,15 @@ See also [keypath](#keypath) and [pred](#pred). nil ``` +`must` can now take multiple arguments, for concisely specifying multiple steps. It navigates to each key, one after another. + +```clojure +=> (select-any (must :a) {:a {:b 2} :c 3}) +{:b 2} +=> (select-any (must :a :b) {:a {:b 2} :c 3}) +2 +``` + `must` can transform to `NONE` to remove elements. ```clojure From 2181c1c2c262148192c870ebec68d951f865fc58 Mon Sep 17 00:00:00 2001 From: Michael Fogleman Date: Mon, 18 Sep 2017 08:37:52 -0400 Subject: [PATCH 2/5] Document 'keypath' multiple arguments. --- List-of-Navigators.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/List-of-Navigators.md b/List-of-Navigators.md index b3456b8..7d41ce4 100644 --- a/List-of-Navigators.md +++ b/List-of-Navigators.md @@ -648,6 +648,15 @@ See also [must](#must) [0 :boo] ``` +`keypath` can now take multiple arguments, for concisely specifying multiple steps. It navigates to each key one after another. + +```clojure +=> (select-one (keypath "out") {"out" {"in" 3}}) +{"in" 3} +=> (select-one (keypath "out" "in") {"out" {"in" 3}}) +3 +``` + `keypath` can transform to `NONE` to remove elements. ```clojure From 473301e89c0c3738a79a16262d9da97555f64f74 Mon Sep 17 00:00:00 2001 From: Michael Fogleman Date: Mon, 18 Sep 2017 08:48:08 -0400 Subject: [PATCH 3/5] Document 'eachnav'. --- List-of-Navigators.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/List-of-Navigators.md b/List-of-Navigators.md index 7d41ce4..e09f4ed 100644 --- a/List-of-Navigators.md +++ b/List-of-Navigators.md @@ -35,6 +35,7 @@ - [cond-path](#cond-path) - [continue-then-stay](#continue-then-stay) - [continuous-subseqs](#continuous-subseqs) + - [eachnav](#eachnav) - [filterer](#filterer) - [if-path](#if-path) - [index-nav](#index-nav) @@ -569,6 +570,14 @@ Navigates to every continuous subsequence of elements matching `pred`. [11 12 20] ``` +## eachnav + +`(eachnav navigator)` + +Turns a navigator that takes one argument into a navigator that takes many arguments and uses the same navigator with each argument. There is no performance cost to using this. + +`keypath`, `must`, and `nthpath` are all implemented using eachnav, making multiple arguments possible. See their documentation here, or look at their implementation in Specter core. + ## filterer `(filterer & path)` From fe634baaddee22e7173cba236f26dce05096090b Mon Sep 17 00:00:00 2001 From: Michael Fogleman Date: Mon, 18 Sep 2017 08:50:58 -0400 Subject: [PATCH 4/5] Document 'nthpath' multiple arguments. --- List-of-Navigators.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/List-of-Navigators.md b/List-of-Navigators.md index e09f4ed..ddddb62 100644 --- a/List-of-Navigators.md +++ b/List-of-Navigators.md @@ -778,6 +778,17 @@ Navigate to the specified indices (one after another). Transform to NONE to remo [1 2] ``` +`nthpath` can now take multiple arguments, for concisely specifying multiple steps. It navigates to each index, one after another. + +```clojure +=> (select [(nthpath 0)] [1 2 3]) +[1] +=> (select [(nthpath 0)] [[0 1 2] 2 3]) +[[0 1 2]] +=> (select [(nthpath 0 0)] [[0 1 2] 2 3]) +[0] +``` + ## parser `(parser parse-fn unparse-fn)` From 5c00a7876d4bd2a1c7316743e5e2cf1b926510d3 Mon Sep 17 00:00:00 2001 From: Michael Fogleman Date: Mon, 18 Sep 2017 09:20:51 -0400 Subject: [PATCH 5/5] Fix arities for multiple arguments. --- List-of-Navigators.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/List-of-Navigators.md b/List-of-Navigators.md index ddddb62..b16eaaa 100644 --- a/List-of-Navigators.md +++ b/List-of-Navigators.md @@ -639,7 +639,7 @@ at that index to the new index, shifting other elements in the sequence. ## keypath -`(keypath key)` +`(keypath & keys)` Navigates to the specified key, navigating to nil if it does not exist. Note that this is different from stopping navigation if the key does not exist. If you want to stop navigation, use [must](#must). @@ -720,7 +720,7 @@ applies updates to the paths in order. ## must -`(must key)` +`(must & keys)` Navigates to the key only if it exists in the map. Note that must stops navigation if the key does not exist. If you do not want to stop navigation, use [keypath](#keypath). @@ -765,7 +765,7 @@ navigated at the structure. ## nthpath -`(nthpath index)` +`(nthpath & indices)` Navigate to the specified indices (one after another). Transform to NONE to remove the element from the sequence.