This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-12-31
Channels
- # adventofcode (15)
- # announcements (8)
- # babashka (16)
- # beginners (48)
- # braveandtrue (5)
- # calva (54)
- # cider (7)
- # clara (8)
- # clj-kondo (3)
- # cljdoc (3)
- # clojure (37)
- # clojure-europe (1)
- # clojure-italy (15)
- # clojure-losangeles (2)
- # clojure-nl (15)
- # clojure-uk (6)
- # clojurescript (145)
- # community-development (53)
- # cursive (20)
- # data-science (8)
- # datomic (23)
- # duct (2)
- # emacs (22)
- # fulcro (16)
- # gorilla (7)
- # graalvm (7)
- # hoplon (1)
- # malli (7)
- # off-topic (8)
- # rewrite-clj (2)
- # ring (9)
- # spacemacs (2)
- # specter (1)
- # tools-deps (25)
- # vrac (1)
This question https://github.com/redplanetlabs/specter/issues/287 got me thinking about how to solve the problem in the general case and I thought it would be nice to have a subselect like nav that allowed transformation to multiple values like srange. While this implementation is broken it better illustrates what I mean:
(sp/defdynamicnav seqsubselect
[& path]
(sp/late-bound-nav
[late (sp/late-path path)]
(select*
[this structure next-fn]
(next-fn (sp/compiled-select late structure)))
(transform*
[this structure next-fn]
(let [select-result (sp/compiled-select late structure)]
(reduce
(fn [structure s]
(i/srange-transform* structure s (inc s) next-fn))
structure
(map #(.indexOf structure %) (reverse select-result)))))))
(sp/transform
[(seqsubselect
[sp/ALL
vector?])]
(fn [structure]
(mapcat
(fn [x]
(concat
(filter odd? x)
[(into [] (filter even? x))]))
structure))
[:a [2 4 6] :b [5 6 7 8] :c [3 5 7] :d [1 2 3 4]])
;; => [:a [2 4 6] :b 5 7 [6 8] :c 3 5 7 [] :d 1 3 [2 4]]