This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-08-05
Channels
- # admin-announcements (3)
- # architecture (1)
- # beginners (16)
- # boot (14)
- # cljsrn (205)
- # clojars (4)
- # clojure (100)
- # clojure-austin (2)
- # clojure-india (1)
- # clojure-poland (7)
- # clojure-russia (95)
- # clojure-spec (25)
- # clojure-uk (127)
- # clojurescript (32)
- # core-async (7)
- # cursive (2)
- # datascript (4)
- # datomic (3)
- # editors-rus (1)
- # emacs (8)
- # events (10)
- # funcool (5)
- # gorilla (2)
- # hoplon (6)
- # jobs (1)
- # lein-figwheel (7)
- # leiningen (2)
- # luminus (11)
- # om (7)
- # onyx (119)
- # other-languages (31)
- # proto-repl (1)
- # proton (37)
- # protorepl (3)
- # re-frame (60)
- # reagent (8)
- # spacemacs (9)
- # specter (21)
- # spirituality-ethics (2)
- # yada (10)
hi, is it possible to implement something similar to a "group-by" operation with specter?
i'd like to do something like
[{:a 1, :b 1} {:a 1, :b 2} {:a 2, :b 2}] -> [{:a 1, :b [1 2]} {:a 2, :b [2]}]
you need to accumulate things while you traverse the collection somewhere, but I can't figure out how (if possible)
@jjcomer: will do once clojars comes back up
@esirola: I'm not sure how to express that with navigation
@nathanmarz: ok thanks a lot
@esirola: I just implemented it as an exercise, not with Specter:
(let [data [{:a 1, :b 1} {:a 1, :b 2} {:a 2, :b 2}]]
#_=> (reduce (fn [acc [k v]] (conj acc {:a k :b (mapv :b v)})) [] (group-by :a data)))
@nathanmarz: Thanks!
What is the reason one path is called FIRST and another MAP-VALS, why not FIRST and SECOND?
@borkdude: MAP-VALS navigates to each value of a map, has nothing to do with second
@nathanmarz: ah, I mean [ALL FIRST] vs [MAP-VALS] - why is there no MAP-KEYS?
there could be a MAP-KEYS that's more efficient than ALL FIRST but I've never needed that
whereas MAP-VALS comes up all the time, so having an optimized version provides a lot of value
you can do (def MAP-KEYS (comp-paths ALL FIRST))
if you want something reusable
pretty much everything in Specter grew out of real use cases