This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-05-02
Channels
- # aws-lambda (5)
- # bangalore-clj (1)
- # beginners (96)
- # boot (66)
- # cider (39)
- # cljsjs (2)
- # cljsrn (5)
- # clojure (265)
- # clojure-android (1)
- # clojure-france (1)
- # clojure-greece (32)
- # clojure-italy (4)
- # clojure-russia (2)
- # clojure-sg (1)
- # clojure-spec (27)
- # clojure-uk (25)
- # clojurescript (88)
- # cursive (4)
- # datomic (31)
- # emacs (96)
- # hoplon (10)
- # immutant (14)
- # jobs (2)
- # luminus (1)
- # lumo (66)
- # off-topic (128)
- # om (8)
- # om-next (2)
- # onyx (9)
- # parinfer (5)
- # re-frame (37)
- # reagent (16)
- # rum (9)
- # schema (3)
- # specter (34)
- # unrepl (8)
- # yada (21)
is there some built-in higher order selector that allows me to write the following: (transform (??? FIRST LAST) (fn [[a b]] (if (> a b) [(str a) b] [a (str b)]) [1 2 3])
=> [1 2 "3"]?
Hey, looking for a way to transform a single value from set into multiple values using a predicate (subset won't help in that case becuase its not a static set of items)
iv tried to use transform with pred but that can replace only a single value and not expand a value into multiple ones
I managed to so by using a reduce in the transform function but that not really using specter
@narkisr you would need a new navigator for that
something like (dynamic-subset even?)
that navigates to the subset of all even values
the definition of subset
should be a good starting point https://github.com/nathanmarz/specter/blob/master/src/clj/com/rpl/specter.cljc#L794
Has anybody looked at odin https://github.com/halgari/odin Any thoughts on how it compares to specter?
@mac from glancing at the readme every example deals with nested maps, so I would want to know if it can handle other data structures / be extensible to user data types
I'm also skeptical of the performance and the expressive power
especially specter's "substructure" navigators, like "srange", "filterer", etc.
a good test use case is incrementing the last odd number in a vector of numbers
@nathanmarz If get the time I will see if I can make that work.
cool, please post whatever you find
I would have expected
(s/select [s/ALL (s/collect-one :a) :b s/DISPENSE #(= % 1)] [{:a "A" :b 1} {:a "AA" :b 1}])
it's producing the right result
DISPENSE
drops collected values
that path is equivalent to [ALL :b #(= % 1)]
what about it?
Ref "Drops all collected values for subsequent navigation" - I understood this to mean values for subsequent navigations to be droped.
"collected values" always refers to values collected via collect
, collect-one
, and VAL
user=> (doc DISPENSE)
-------------------------
com.rpl.specter/DISPENSE
Drops all collected values for subsequent navigation.
nil
user=> (doc collect-one)
-------------------------
com.rpl.specter/collect-one
Adds the result of running select-one with the given path on the
current value to the collected vals.
nil
user=> (doc collect)
-------------------------
com.rpl.specter/collect
Adds the result of running select with the given path on the
current value to the collected vals.
nil
user=> (doc with-fresh-collected)
-------------------------
com.rpl.specter/with-fresh-collected
Continues navigating on the given path with the collected vals reset to []. Once
navigation leaves the scope of with-fresh-collected, the collected vals revert
to what they were before.
nil
terminology is consistent
I think you're looking for (select [ALL #(= 1 (:b %)) :a] data)
or (select [ALL (selected? :b #(= 1 %)) :a] data)
Thanks. I take it then there is no "do not return any values navigated to after this point just use it for selecting" navigator.
correct
@nathanmarz Gave halgari anouthe look. No obvious way of solving the use case you mentioned.