A guess all my talks are Assums?
Oh, and good morning!
Morsning korsning!
good, bright and crisp morning
So with @borkdudeβs and @slipsetβs help I sort of get some of the rationale for transducers. Still need to understand the mechanics. I found the first course in a series about transducers by Tim Baldridge. But it didn't even reach the point where a transducer was used. π I'll check that reference page out first and see where that lands me.
@pez the original talk is probably the most informative one: https://www.youtube.com/watch?v=6mTbuzafcII
morning
The audio gets better after the first 10 seconds
βallo!
I really loved Tim's transducer explanations. That's when it all clicked for me.
Iβll need to decide what I need the most. Getting transducers to click for me or the money. π
I mostly just use transducers where I would have used ->>
someone wrote a clj-kondo hook for that: https://github.com/borkdude/clj-kondo/issues/323#issuecomment-691247062
I always worry that there is a lurking problem with eductions
(deftype Eduction [xform coll]
Iterable
...
clojure.lang.IReduceInit
...
clojure.lang.Sequential)
in that Iterable
is supposed to give you an infinite number of usable Iterator
objects, but IReduceInit
does not provide that kind of implication; it might just be a one-shot thing@ben.hammond What's the catch? eductions can behave as iterable objects, but also as efficiently reducible objects.
I've see eductions used where you pass in a reducible as the coll
, but then other parts see the Iterable
interface flaunted by the eduction, try to use it as a sequential, and wonder why it oges horribly wrong
(clojure.lang.TransformerIterator/create xform (clojure.lang.RT/iter coll))
might blow up if coll
is just an IReduceInit
but not a sequentialcreates a little unexploded Exception to be passed around
good point. what's an example of a coll that's not a sequential, but does satisfy IReduceInit?
well anything that you created using
(reify IReduceInit
for examplebut I'm conflating two seperate issue here
β’ Don't create eduction with colls that do not support Iterable
is not the same as
β’ How do you distinguish IReduceInits
that are reusable from those that are one-shot
reify does support implementing multiple protocols/interfaces, but I guess you could forget to implement both
I worked on a project where we had a Cognitect consultant who did exactly this; it creates an issue because when their Clojure-fu so far outstrips the team's it takes quite a while to figure out the problem
I guess you could also implement your own type on top of IReduceInit:
(deftype OneShot [xforms coll] IreduceInit ...)
which you can then feed to (into [] (OneShot. ...))
and you could similiarly create (deftype EductionReduceOnly
problem comes in when the logging framework
β’ sees the Sequential
on the eduction
tries to use it to write a log string an blows up your server
OR
β’ correctly uses the one-shot IReduceInit
, but thus exhausts the reducible so its not available to do the real work
(for example, all sorts of insidious problems can arise from this)
Ah, that's interesting! And very helpful for me. Thanks!
Doesn't he have a free one where he explains the functions
good moaning
there seems to be missing an emoji for > moan is π© the closest we can get?
maybe π¬
which (interestingly) looks like a USB-C plug
Not sure which functions? I found a fee one where he starts to talk about transducers, but the rest of that series is not free.
yeah, most of the talks early on just confused me as they talked a lot about the internals of transducers, whereas what I needed to know was that they were faster, created less garbage, and could replace most of my ->>
Maybe a picture of an English man pretending to be a French police officer?
Ha! I've now rewritten a few transduce
examples to ->>
. A bit backward, you might think, but it seems to help me figure out how to use transduce
. Thanks @otfrom!
π
I think I probably use into
more than transduce
, but I usually just want to do something horrible to a seq and have it turn into a vector
Yeah, while I do want to have transduce in my tool chest, the most important thing to me right now is to be able to read more Clojure code.
I do find that into and transduce help me to create and read more clojure code. It makes it easy to create composable transformation pipelines