This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-05-25
Channels
- # adventofcode (3)
- # aleph (24)
- # architecture (8)
- # beginners (53)
- # boot (34)
- # cider (7)
- # clara (68)
- # cljs-dev (6)
- # cljsrn (3)
- # clojars (10)
- # clojure (71)
- # clojure-germany (2)
- # clojure-italy (10)
- # clojure-nl (25)
- # clojure-serbia (4)
- # clojure-spec (13)
- # clojure-uk (48)
- # clojurescript (31)
- # core-async (62)
- # cursive (13)
- # datomic (4)
- # duct (76)
- # editors (4)
- # fulcro (2)
- # immutant (1)
- # instaparse (1)
- # jobs (1)
- # lein-figwheel (1)
- # mount (1)
- # off-topic (12)
- # onyx (8)
- # re-frame (10)
- # reagent (84)
- # reitit (2)
- # ring (2)
- # shadow-cljs (159)
- # spacemacs (2)
- # specter (17)
- # sql (14)
- # tools-deps (10)
- # yada (15)
@huthayfa.ainqawi it'll be easier to help you if you give an example of the input and output you want
@nathanmarz input {"properties": { "assets": {"target-key"}}} output: [properties assets target-key]
input ({"properties": { "assets": {"target-key"}}}, target-key) output: [properties assets target-key]
@huthayfa.ainqawi that input isn't well formed
Hi, how do you navigate data structures with specter lazily? What I'm trying to do is select the first item with matching predicate like this:
(->> very-long-vector
(transform [ALL] my-fn)
(select-first [ALL my-pred?]))
I believe doing that won't be very efficient since specter will "realize" each step@funyako.funyao156 there is no lazy computation with specter
but if you do (select-first [ALL (view my-fn) my-pred?] very-long-vector)
it will stop traversing the vector as soon as my-pred?
is satisfied
@nathanmarz so the select-first
behave similar to (first (filter pred ...))
in terms of "lazy like" ? Thanks!
@funyako.funyao156 it works via early termination
it uses reduced
/`reduced?` under the hood
@nathanmarz Thanks alot for answering me! Last one, sorry if I ask a lot. How do you return default value using select-first
if no matching element found, for example:
(select-first [ALL keyword? (nil->val :foo/bar)] [1 2 3])
That still return a nil.that code never gets to the nil->val
navigator since keyword?
filters everything out
you can just do (or (select-first [ALL keyword?] [1 2 3]) :foo/bar)
no problem, that's what this channel is for
user=> (def MAP-VALS+ (path ALL (collect-one FIRST) LAST))
#'user/MAP-VALS+
user=> (select-any [MAP-VALS+ MAP-VALS+ MAP-KEYS] {"properties" { "assets" {"target-key" "value"}}})
["properties" "assets" "target-key"]