Fork me on GitHub
#specter
<
2016-10-20
>
joshkh15:10:17

howdy! just curious about a behaviour in the following example:

(s/select [:a s/ALL (juxt :start :end)]
                  {:a [{:start 1 :middle 9 :end 2} {:start 3 :middle 9 :end 4}]})
yields [{:start 1, :middle 9, :end 2} {:start 3, :middle 9, :end 4}] when i would have expected just :start and :end keys in the resulting maps.

joshkh15:10:55

i thought multipath might allow me to collect the two values but this throws an exception in cljs:

(s/select [:a s/ALL (s/multi-path :start :end)]
                  {:a [{:start 1 :middle 9 :end 2} {:start 3 :middle 9 :end 4}]})

joshkh15:10:43

when i really just wanted [[1 2] [3 4]

joshkh15:10:11

i could just throw an anonymous function in there, something like (vals (select-keys...

exupero15:10:30

In the juxt example, I’m guessing the function is treated as a predicate, so it returns anything for which that predicate returns a truthy result, not the truthy result itself.

joshkh15:10:56

ah, that makes sense

joshkh15:10:38

(and i lied about the anonymous function - like you said it's treated as a predicate)

nathanmarz15:10:19

@joshkh what exception are you getting? that works fine for me in a cljs repl

joshkh15:10:37

specter.cljc?rel=1476963781628:1049 Uncaught TypeError: G__36053.select_STAR_ is not a function

joshkh15:10:19

using [com.rpl/specter "0.13.0"]

nathanmarz15:10:53

yea that bug is fixed in master

nathanmarz15:10:57

try 0.13.1-SNAPSHOT

joshkh15:10:36

it worked! thanks 🙂

nathanmarz15:10:38

also if you want to get [[1 2] [3 4]] as the result do this:

(select [:a s/ALL (s/collect-one :start) :end]
        {:a [{:start 1 :middle 9 :end 2} {:start 3 :middle 9 :end 4}]})

joshkh15:10:56

oh right. i had tried calling collect-one for each respective key but couldn't figure out how to "drop" the rest from the selection resulting in [1 3 {entire-node}]

joshkh15:10:59

as always, thanks for the help

nathanmarz15:10:22

no problem, glad I was helpful