Fork me on GitHub
#specter
<
2016-10-11
>
spieden21:10:42

some specter golf for you all: how to select triples from a nested map where values are nil? e.g. {:foo {:bar nil :bom 1}} -> [:foo :bar]

spieden21:10:41

hmm maybe selected? + some subselects

nathanmarz22:10:46

@spieden use value collection

spieden22:10:07

trying something with multi-path right now but not panning out

nathanmarz22:10:28

(select [ALL (collect-one FIRST) LAST ALL (selected? LAST nil?) FIRST] data)

spieden22:10:55

perfect, thanks!

spieden22:10:02

(works and now i’ll try to understand it)

nathanmarz22:10:40

can make it recursive too if you want to handle arbitrarily nested maps

spieden22:10:44

i think i understand it — didn’t realize that selected? would propagate back like that

spieden22:10:56

is this what distinguishes it from filterer?

nathanmarz22:10:09

selected? expresses a filter predicate in terms of a path

spieden22:10:13

also was trying to use collect instead of collect-one

nathanmarz22:10:03

filterer navigates to result of running filter using the path as a filter predicate

nathanmarz22:10:15

(`filterer` uses selected? in its implementation)

nathanmarz22:10:59

(defdynamicnav filterer
  [& path]
  (subselect ALL (selected? path)))

nathanmarz22:10:24

(transform (filterer odd?) reverse [1 2 3 4 5 6 7]) => [7 2 5 4 3 6 1]