Fork me on GitHub
#specter
<
2017-03-21
>
luxbock14:03:37

what's wrong with my implementation of a take-nth navigator: https://gist.github.com/luxbock/a6a1323497a02e36b09dec624c57b3ab ?

luxbock14:03:22

I am using (:refer-clojure :exclude [take-nth]) so it's not colliding with the clojure.core version

luxbock14:03:42

using transform works fine

luxbock14:03:11

argh, I'm an idiot, of course I'm calling take-nth inside my select*

luxbock16:03:09

if I want my navigators to respect NONE do I need to implement that for every navigator?

luxbock16:03:11

is that something that could be done automatically for me, or am I missing something obvious?

nathanmarz16:03:34

how to handle transformations to NONE is completely navigator specific

nathanmarz16:03:07

for keypath it does a dissoc, for ALL it filters it from reconstruction, for nthpath it removes from the sequence, etc.

luxbock16:03:42

right, makes sense

nathanmarz16:03:19

looking at how those navigators implement it would be instructive I think

luxbock16:03:48

what is the extra argument vals that defrichnav uses for select and transform?

nathanmarz16:03:10

those are the collected values

nathanmarz16:03:26

like from collect, collect-one

luxbock16:03:17

ah I see, thanks

nathanmarz16:03:16

navigators that need to be defined using defrichnav are special cases

nathanmarz16:03:51

keypath does it as an optimization since Clojure/JVM aren't smart enough to inline this particular case

luxbock16:03:19

I'm trying to figure out how I could implement every-nth that respects NONE but it feels very difficult: https://gist.github.com/luxbock/69b766830144e4bdb767923ba7fb2f9c

nathanmarz16:03:53

you'll need a totally different approach

nathanmarz16:03:01

better to construct a new vector from scratch

nathanmarz16:03:27

elements that aren't at the nth indices go in unchanged, and for the others you apply next-fn and filter out ones that transform to NONE

nathanmarz16:03:35

something similar for lists

nathanmarz16:03:44

that's basically how ALL works

luxbock16:03:20

yeah, I'm trying to learn from the specter native navigators but they are so heavily optimized that it's taking some time 🙂

nathanmarz16:03:27

you should be able to do something very similar

luxbock16:03:10

yeah, I'll keep trying, seems like an appropriately challenging example for me to level up on

nathanmarz16:03:10

looks like you're understanding how navs work pretty well

luxbock16:03:03

do you see specter still adding more navigators (such as these) or would you rather people see publish them as utility libraries?

luxbock16:03:13

I think it's easy enough to write navigators that are very naive, but making them highly performant, versatile (in support for all possible datastructures) and respecting NONE is a lot of work, so I would definitely be happy to share the workload with others

luxbock16:03:50

I remember a while back you mentioned that transducers that use comp are in some cases slower than just writing the same tranformation sequentially, because of the overhead of comp, and you could improve the performance by pre-compiling the composed transducer

luxbock16:03:53

how would one compile a transducer, if I already know what it should do and don't need to compose it further using other transducers?

nathanmarz16:03:51

@luxbock these don't seem core enough to me to go into specter core

nathanmarz16:03:29

also some of these may be superseded by stateful navigators if that's ever implemented https://github.com/nathanmarz/specter/issues/121

nathanmarz16:03:07

not sure I understand your question about transducers

nathanmarz16:03:21

you precompile by calling comp in a central spot

nathanmarz16:03:51

the problem is you can't precompile anything that requires the dynamic context (like local variables)

nathanmarz16:03:11

e.g. (comp (map some-local-arg) (filter even?))

nathanmarz16:03:16

the best you can do is precompile sequences of static transducers for reuse

nathanmarz16:03:46

in theory, transducers could use a similar inline compilation/caching strategy as specter to make this automatic

luxbock16:03:41

I see, yeah stateful navigators look very interesting