This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-01-12
Channels
- # aws (21)
- # aws-lambda (8)
- # beginners (53)
- # boot (56)
- # braveandtrue (1)
- # cider (49)
- # cljs-dev (8)
- # cljsjs (1)
- # cljsrn (57)
- # clojure (403)
- # clojure-austin (17)
- # clojure-dusseldorf (10)
- # clojure-greece (9)
- # clojure-spec (57)
- # clojure-uk (144)
- # clojurescript (60)
- # datomic (149)
- # docker (1)
- # emacs (1)
- # hoplon (23)
- # humor (1)
- # jobs (1)
- # leiningen (2)
- # luminus (1)
- # off-topic (1)
- # om (24)
- # om-next (15)
- # onyx (23)
- # protorepl (2)
- # re-frame (58)
- # reagent (90)
- # remote-jobs (1)
- # ring-swagger (4)
- # slackpocalypse (1)
- # spacemacs (2)
- # specter (18)
- # untangled (4)
- # vim (1)
- # yada (27)
Early access to Specter Koans: https://github.com/gdeer81/specter-koans currently only covers select and navigation and only takes about 10 minutes to complete but I'm going to constantly be adding more
Is there a bug here?
"FIRST is obvious on collections except for on a map"
(= true (= [[0 :a]] (select FIRST (sorted-map 0 :a 1 :b))))
"You will also run into the same thing with LAST on a map"
(= false (= [1 :b] (select LAST (sorted-map 0 :a 1 :b))))
As you can’t guarantee order in a map, you can't know in advance if the result will be true or false. I guess this might be confusing for some people.because (though this could just be lucky)
(first (sorted-map 0 :a 1 :b))
=> [0 :a]
(last (sorted-map 0 :a 1 :b))
=> [1 :b]
(sp/select sp/FIRST (sorted-map 0 :a 1 :b))
=> [[0 :a]]
(sp/select sp/LAST (sorted-map 0 :a 1 :b))
=> [[1 :b]]
@james that one was actually pulled from the example https://github.com/nathanmarz/specter/wiki/List-of-Navigators#first but it looks like I used select instead of select-one
@bfabry yeah this koan has taught me to pay attention to which select function I'm using lol
checking out specter, looks great so far. one thing i'm trying to figure out is, given a nested data structure and a leaf node (e.g. :foo
), can specter compute the path to that node for me?
@devth you're looking for this: https://github.com/nathanmarz/specter/issues/49
not implemented
you can do it manually for some cases using value collection (`collect` and collect-one
)
doesn't collect
require that you know the path ahead of time? e.g. searching for :qux
in a given structure – [:foo/bar {:baz/a [:qux]}]
as an example
@devth there's an example above of what I mean
here:
(defnav ALL-INDEXED []
(select* [this structure next-fn]
;; fill this in
)
(transform* [this structure next-fn]
(map-indexed
(fn [i v]
(second (next-fn [i v])))
structure
)))
(def MyPath
(recursive-path [] p
(cond-path map? [ALL (collect-one FIRST) LAST p]
vector? [ALL-INDEXED (collect-one FIRST) LAST p]
STAY STAY)))
(transform MyPath
(fn [& vals] vals)
{:a {:b [:apple :orange :pear]
:c [:juice]}
:e [:cat :dog]})
@nathanmarz awesome, thanks!
if you filled in select*
for ALL-INDEXED
then you could do (select MyPath data)
to retrieve the paths to each leaf element