From c6046aa874116aeffbcd059b68d63a0fdd5d4ede Mon Sep 17 00:00:00 2001 From: Nathan Marz Date: Sat, 12 Sep 2015 14:15:35 -0400 Subject: [PATCH] parameterize view and make a parameterized version of using a function called pred --- src/com/rpl/specter.cljc | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/com/rpl/specter.cljc b/src/com/rpl/specter.cljc index 3d9f390..c13c26f 100644 --- a/src/com/rpl/specter.cljc +++ b/src/com/rpl/specter.cljc @@ -203,7 +203,12 @@ (assoc structure key (next-fn (get structure key))) )) -(defn view [afn] (i/->ViewPath afn)) +(defparamspath view [afn] + (select* [this structure next-fn] + (next-fn (afn structure))) + (transform* [this structure next-fn] + (next-fn (afn structure)) + )) (defn selected? "Filters the current value based on whether a selector finds anything. @@ -275,6 +280,16 @@ (transform* [aset structure next-fn] (i/filter-transform aset structure next-fn))) +(defparamspath + ^{:doc "Keeps the element only if it matches the supplied predicate. This is the + late-bound parameterized version of using a function directly in a path."} + pred + [afn] + (select* [this structure next-fn] + (i/filter-select afn structure next-fn)) + (transform* [this structure next-fn] + (i/filter-transform afn structure next-fn))) + (defn collect [& path] (pathed-collector [late path] (collect-val [this structure]