This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-07-20
Channels
- # aleph (4)
- # beginners (47)
- # boot (22)
- # cider (7)
- # clara (1)
- # cljs-dev (8)
- # cljsrn (21)
- # clojure (180)
- # clojure-argentina (13)
- # clojure-gamedev (1)
- # clojure-italy (5)
- # clojure-poland (4)
- # clojure-russia (17)
- # clojure-spec (19)
- # clojure-uk (33)
- # clojurescript (107)
- # cursive (61)
- # data-science (1)
- # datomic (7)
- # emacs (69)
- # euroclojure (1)
- # graphql (1)
- # hoplon (11)
- # immutant (43)
- # jobs (1)
- # leiningen (3)
- # off-topic (5)
- # om (10)
- # onyx (2)
- # parinfer (52)
- # pedestal (11)
- # re-frame (31)
- # reagent (23)
- # ring-swagger (3)
- # schema (2)
- # specter (7)
- # unrepl (9)
Hello everyone. I want to do the following transformation:
[[:a :b :c] [:d] [:e :f] [:g]] => [[0 1 2] [3] [4 5] [6]]
In other words, I want to enumerate elements in two-levels-deep nested structure. I managed to achieve this with subselect
:
(setval (subselect ALL ALL) (iterate inc 0) [[:a :a :a] [:b] [:c :c] [:d]])
Is there a better way than using subselect
here? I was looking for something like FLATMAP
navigator that is like ALL
but splices each sequence into top-level view.@alexyakushev that's a perfect solution
you could define FLATMAP
with something like:
(def FLATMAP
(recursive-path [] p
(if-path sequential?
[ALL p]
STAY
)))
Thanks, Nathan! A quick follow-up question. Is there a way to transform a vector so that the transform-fn receives an index of the element? Like map-indexed
. All I could Google was https://github.com/nathanmarz/specter/issues/169, but in that case the iterable element was a map, where keys are more easily obtained.
not in specter core
you could define a navigator similar to ALL
which navigates to [index value]
Hm, I didn't know it is this easy to define new navigators 🙂 This is excellent, thank you!