specter

Latest version: 1.1.3
nathanmarz 2018-05-25T00:33:31.000081Z

@huthayfa.ainqawi it'll be easier to help you if you give an example of the input and output you want

huthayfa 2018-05-25T02:00:54.000288Z

@nathanmarz input {"properties": { "assets": {"target-key"}}} output: [properties assets target-key]

huthayfa 2018-05-25T02:01:30.000068Z

input ({"properties": { "assets": {"target-key"}}}, target-key) output: [properties assets target-key]

nathanmarz 2018-05-25T02:42:27.000243Z

@huthayfa.ainqawi that input isn't well formed

huthayfa 2018-05-25T03:20:27.000175Z

input ({"properties": { "assets": {"target-key" "value"}}}, target-key) nested map

fmn 2018-05-25T12:43:34.000546Z

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

nathanmarz 2018-05-25T13:23:00.000445Z

@funyako.funyao156 there is no lazy computation with specter

nathanmarz 2018-05-25T13:23:34.000252Z

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

fmn 2018-05-25T13:43:11.000397Z

@nathanmarz so the select-first behave similar to (first (filter pred ...)) in terms of "lazy like" ? Thanks!

nathanmarz 2018-05-25T14:20:07.000186Z

@funyako.funyao156 it works via early termination

nathanmarz 2018-05-25T14:20:41.000006Z

it uses reduced/`reduced?` under the hood

fmn 2018-05-25T14:22:32.000149Z

@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.

nathanmarz 2018-05-25T14:28:01.000535Z

that code never gets to the nil->val navigator since keyword? filters everything out

nathanmarz 2018-05-25T14:28:21.000254Z

you can just do (or (select-first [ALL keyword?] [1 2 3]) :foo/bar)

fmn 2018-05-25T14:29:08.000807Z

Right, silly me. Sorry I ask alot! Thanks again!

nathanmarz 2018-05-25T14:30:24.000846Z

no problem, that's what this channel is for

nathanmarz 2018-05-25T14:32:44.000345Z

@huthayfa.ainqawi

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"]