Fork me on GitHub
#specter
<
2018-03-09
>
razum2um15:03:41

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}

nathanmarz15:03:11

@razum2um

(transform [(must :loc) ALL] inc data)

razum2um15:03:29

@nathanmarz btw, I had an idea about the vector as a forth program, did you think about this?

nathanmarz15:03:15

@razum2um no, what do you mean?

razum2um16:03:15

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)

razum2um16:03:03

I understand implementing VM for data traversal is not easy 😅 but just wanted to share this

razum2um16:03:43

just on the spot: e.g. in this way we could even allow some recursion steps in traversal

razum2um16:03:53

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

nathanmarz16:03:47

that would increase the complexity of specter by 1000x

nathanmarz16:03:10

specter is not a language, it's just an interface and an efficient method for composing them

nathanmarz16:03:43

there's no known use cases it doesn't handle, so there's no reason to do something like that

razum2um16:03:45

don’t push you, just wanted to hear your thoughts

razum2um16:03:10

thanks for your efforts btw 👍

razum2um16:03:49

is it ok if I’ll PR to the readme.md with must example?

nathanmarz16:03:16

not sure what to do with the readme, it's kind of just a random exploration of different kinds of manipulations

nathanmarz16:03:22

I don't think making that section longer than it already is will improve things

nathanmarz16:03:31

the wiki is pretty good nowadays

nathanmarz16:03:36

so I just point people there

razum2um16:03:23

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?

razum2um16:03:50

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)

nathanmarz16:03:59

@razum2um this is the categorization I use when thinking of navigators: https://github.com/nathanmarz/specter/wiki/Cheat-Sheet

razum2um16:03:05

yeah, saw it. is there any other stopping word like must?

nathanmarz16:03:48

ALL, MAP-KEYS, MAP-VALS will stop if there's nothing in the collection

nathanmarz16:03:51

STOP explicitly stops

nathanmarz16:03:59

terminal navigators explicitly stop

nathanmarz16:03:27

set-elem and map-key stop if the elem/key isn't there

razum2um16:03:32

ok, thanks 👍

nathanmarz16:03:51

FIRST/`LAST` stop if the sequence is empty