This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-12-15
Channels
- # adventofcode (121)
- # bangalore-clj (5)
- # beginners (46)
- # boot-dev (9)
- # cider (20)
- # cljs-dev (7)
- # cljsrn (1)
- # clojure (341)
- # clojure-austin (7)
- # clojure-greece (144)
- # clojure-india (3)
- # clojure-italy (5)
- # clojure-spain (1)
- # clojure-spec (34)
- # clojure-sweden (3)
- # clojure-uk (90)
- # clojurescript (24)
- # core-async (1)
- # core-logic (7)
- # cursive (108)
- # datascript (2)
- # datomic (39)
- # events (1)
- # fulcro (225)
- # graphql (8)
- # hoplon (86)
- # instaparse (12)
- # jobs-discuss (2)
- # jvm (4)
- # keechma (1)
- # lein-figwheel (2)
- # leiningen (12)
- # off-topic (26)
- # onyx (35)
- # other-languages (1)
- # pedestal (3)
- # planck (11)
- # re-frame (12)
- # reagent (12)
- # reitit (5)
- # spacemacs (48)
- # specter (29)
- # sql (2)
- # test-check (1)
- # unrepl (71)
i have a grid
, which is a vector of vectors of values; those values are either numbers or nil
i’d like to write a specter query that gets me the indexes of all non-nil elements in grid
i can get the non-nil elements themselves by doing
(select [ALL ALL (comp not nil?)]
(@app-state :grid))
which gives me eg (8 2 3 5 7)
i.e. a list of the locations of those non-nil values in the grid, encoded as x-y pairs
the vanilla clojure code i have to do this is
(apply concat
(for [x (range (count grid))]
(for [y (range (count (grid x)))
:when (not (nil? (get-in grid [x y])))]
[x y]))))
, but i have a comment above it saying “; xxx is there a way to do this in specter”, so here i am 🙂 thanks!@jrheard like this: (select [INDEXED-VALS (collect-one FIRST) LAST INDEXED-VALS (selected? LAST some?) FIRST] grid)
will be a lot faster than that clojure code too
@nathanmarz The dependency chain we discussed yesterday is a step closer to completion, the pull request on suchwow was accepted, I've created a ticket on midje and we're waiting for build to get deployed to clojars for suchwow (https://github.com/marick/Midje/issues/427)
@mbjarland ok, that's good
btw, have you tried just overriding the dependency with the latest version? should make the warning go away
@nathanmarz no haven’t done that yet and really, it’s just a warning during a test run so not that big a deal to begin with. I’m happy to wait for the transitive chain to percolate up to midje
i don’t yet understand what the collecting-values is system is / how it works, will read the docs more closely!
the README makes it look pretty clear, i think i’ve just gotta play around with specter some more to build up some muscle memory and get to a point where this feels more natural 🙂
the examples at https://github.com/nathanmarz/specter/wiki/List-of-Navigators#collect are v helpful
@jrheard collected values are a vector that is passed along through navigation
you can see the interface here: https://github.com/nathanmarz/specter/blob/master/src/clj/com/rpl/specter/protocols.cljc#L3
and the result of the selection is basically (concat collected-values value-you-navigated-to) ?
conj
, not concat
thanks again for the help with my grid example, i wouldn’t have come up with that specter code but it makes a lot of sense to me now!