Fork me on GitHub
#specter
<
2016-06-16
>
nathanmarz14:06:31

@codonnell @thomasdeutsch that bug you guys ran into yesterday is now fixed in master

nathanmarz14:06:40

also deployed 0.12.0-SNAPSHOT to clojars if you want to use it

aengelberg14:06:47

@nathanmarz I'm curious why select* really needs each navigator to return one of its navigated values as the return value. If you really want select-any, you could traverse with the final continuation being to deliver to a promise (where only the first value matters).

nathanmarz14:06:23

it's the most efficient way

nathanmarz14:06:43

don't need to create any anonymous function, don't need to write anywhere

nathanmarz14:06:39

an anonymous function that closes over local environment requires object creation and field setting

nathanmarz14:06:09

for cases like (select-any [:a :b :c] {:a {:b {:c 1}}}) these things make a noticeable difference

Chris O’Donnell19:06:34

@nathanmarz: (reduce afn init (traverse apath structure)) should always return the same thing as (reduce afn init (select apath structure)), right? But it is more memory efficient because it only store the reduction value, rather than instantiating the entire seq?

nathanmarz19:06:49

@codonnell: that's exactly right

nathanmarz19:06:49

not just memory efficient but also faster

nathanmarz19:06:41

also useful if you want something like a set of results back, e.g. (into #{} (traverse ...))

Chris O’Donnell20:06:32

Is collected? the same as pred, but it takes the collected values as input rather than the structure?

Chris O’Donnell20:06:55

alright, these new operations should be pretty easy to write up

Chris O’Donnell21:06:06

I pushed the 0.12.0 macros and navigators up to https://github.com/codonnell/specter/wiki/List-of-Macros. Pretty sure they are accurate.

Chris O’Donnell21:06:57

perhaps jumping the gun, but it's there on my wiki if needed

nathanmarz21:06:22

added another traverse example and merged in

luxbock23:06:55

how would I implement REST? i.e. (select-one REST [1 2 3]) => [2 3]?

luxbock23:06:22

I can use srange but then I need to know the length of the collection in the selector

luxbock23:06:56

I was trying to figure out how to do it by looking at ALL and FIRST but the code looks so optimized that I can't really figure out how to write it

Chris O’Donnell23:06:20

@luxbock: you should be able to do it with defnav (see https://github.com/nathanmarz/specter/wiki/List-of-Macros#defnav for a similar example)

Chris O’Donnell23:06:40

I'm not sure if there's a better way to do it

Chris O’Donnell23:06:08

@luxbock: (select (transformed STAY rest) (range 10))

Chris O’Donnell23:06:25

no, (select (view rest) (range 10))

Chris O’Donnell23:06:40

pretty sure (view rest) is optimal