4 ms·
I am not a Clojure programmer, and am pretty skeptical of LISPs and FP more generally, but i have to say that transducers are pretty great. The descriptions of
by twic 4y ago
I am not a Clojure programmer, and am pretty skeptical of LISPs and FP more generally, but i have to say that transducers are pretty great. The descriptions of them, and the way the interface is expressed, are a bit off-putting, but once you grok them they're actually simple and useful.
They occupy the same space as Java's streams, but manage to do the same stuff with a smaller, more generic, more extensible interface, that can do more stuff (eg intermediate stages get told when input is finished). I'm jealous.
EDIT: IIUC, in Java terms, Clojure's "reducing functions" are like Collector, and a transducer is a function which takes a Collector and returns another one. There is then a little bit of top-level sugar so you can give a sequence of transducers, terminating in a concrete reducing function, and get back a reducing function which itself feeds things through the chain of reducing functions built by the transducers. You could probably replicate this in Java, but it might be too clunky even for Java programmers.
- janetacarr 4y agoTransducers are great! They were an small obsession of mine last week as I wrote an accompanying blog post to demystify them.
- twic 4y agoAha, this one i suppose (your blog does not have a browseable index, although it does have search): https://blog.janetacarr.com/clojure-transducers-your-composable-big-data-pipelines/ https://blog.janetacarr.com/clojure-transducers-your-composa... Personally, i would say that a blog post which starts "We can think of a transducer as a context-independent transformation composed of, say, many reducers" and then starts adding parentheses is not really demystifying. But perhaps i am not the target audience.
- janetacarr 4y agoOh yeah. If you didn't know what a reducer was, the article might be a bit confusing, eh?
- twic 4y agoI couldn't stop myself having another go at transducers in Java, this time sticking more closely to using collectors: https://gist.github.com/tomwhoiscontrary/1d4799fb85b4890a96edd2c01f761b15 https://gist.github.com/tomwhoiscontrary/1d4799fb85b4890a96e...