Fork me on GitHub
#code-reviews
<
2020-09-11
>
jjttjj12:09:50

How do people feel about these transducers I've been playing with: https://gist.github.com/jjttjj/4e4572a1e57b0b59db2e3e554a272c12 The idea is to be able to aggregate values on a stream. is it bad to just use map with some closed over state like this?

👍 3
phronmophobic18:09:52

both seem fine in principle. i think the implementation doesn’t adhere to transducer rules since state is created when you call map-prev instead of when it’s connected to a process

phronmophobic18:09:07

(def step (map-prev vec)) you're supposed to be able to reuse step, but the way it's currently written would reuse the same state

jjttjj18:09:50

Oh yeah, that makes sense, so I guess that shortcut doesn't work and I need to actually put the state inside the outermost transducer function

👍 3
phronmophobic18:09:25

but both seem useful

phronmophobic18:09:57

based on the usage, not sure if it would be better to have map-prev act more like: (map f coll (rest coll))

👍 3
phronmophobic18:09:35

which only looks at values that have previous values

jjttjj18:09:45

oh yeah that might be better, gotta think about that a bit

Ben Sless10:09:56

map-prev looks a lot like reductions 🙂