is there a way to express this better?
=> (transform [(if-path [#(contains? % :loc)] [:loc ALL])] inc {:x 1})
{:x 1}
=> (transform [(if-path [#(contains? % :loc)] [:loc ALL])] inc {:loc [1]})
{:loc [2]}
don’t want extra key after simple
=> (transform [:loc ALL] inc {:x 1})
{:x 1, :loc nil}
thanks!
@nathanmarz btw, I had an idea about the vector as a forth program, did you think about this?
@razum2um no, what do you mean?
currently the library api interface looks convenient but adhoc, I feel there shoud be case out there which cannot fit into vector. I thought we could imagine the traversal as “bytecodes” steps to the lib (interpretator)
I understand implementing VM for data traversal is not easy 😅 but just wanted to share this
just on the spot: e.g. in this way we could even allow some recursion steps in traversal
example2: my request above in this approach could look like (transform [:loc >nil? <STOP ALL] inc {:x 1})
where >nil?
puts on stack if loc
return value is nit <STOP
pops and shortcuts path if last val was true
that would increase the complexity of specter by 1000x
yeah 🙂
specter is not a language, it's just an interface and an efficient method for composing them
there's no known use cases it doesn't handle, so there's no reason to do something like that
don’t push you, just wanted to hear your thoughts
thanks for your efforts btw 👍
is it ok if I’ll PR to the readme.md with must
example?
sure thing
not sure what to do with the readme, it's kind of just a random exploration of different kinds of manipulations
I don't think making that section longer than it already is will improve things
the wiki is pretty good nowadays
so I just point people there
and to answer your question about recursion, see https://github.com/nathanmarz/specter/wiki/Using-Specter-Recursively
hm, yes, I think now it’s quite too special example for readme.. but here is the point (from wiki) > Note that must stops navigation I think there should be a list with such “stopping” things, wdyt?
still, here you are https://github.com/nathanmarz/specter/pull/249
I think we have ~300 people here and readme should represent most common used cases. e.g. in same format as in clojuredocs (crowd-examples, maybe on same engine, afair it’s oss)
@razum2um this is the categorization I use when thinking of navigators: https://github.com/nathanmarz/specter/wiki/Cheat-Sheet
yeah, saw it. is there any other stopping word like must
?
ALL
, MAP-KEYS
, MAP-VALS
will stop if there's nothing in the collection
STOP
explicitly stops
terminal
navigators explicitly stop
set-elem
and map-key
stop if the elem/key isn't there
ok, thanks 👍
FIRST
/`LAST` stop if the sequence is empty