Welcome! Please see the About page for a little more info on how this works.

+1 vote
in Clojure by

Doseq is currently a good way to execute a lazy sequence and perform side-effects. It would be nice to have a matching macro for transducers.

Approach: The included patch simply calls transduce with the provided xform, collection, and a reducing function that throws away the accumulated value at each step. The value from each reducing step is bound to the provided symbol. A shorter arity is provided for those cases when no xform is desired, but fast doseq-like semantics are still wanted.

Patch: CLJ-1523-1.patch

7 Answers

+1 vote
by

I like the idea of this suggestion, and I think it would be useful, but I also agree with both comments. The current patch introduces an uintuitive binding taking three elements,which is a bit surprising. Which is why I like the suggestion of adding an arity to run! which takes an additional xf like (run! proc xf coll). That mimics how into works already, so it feels intuitive.

0 votes
by

Comment made by: wagjo

How about making xform parameter optional? And you have a typo in docstring example, doseq -> doreduced.

0 votes
by

Comment made by: halgari

Good point, fixed typeo, added other arity.

0 votes
by

Comment made by: gshayban

perhaps another arity on run!

0 votes
by

Comment made by: michaelblume

Fixed patch to apply to master

0 votes
by

Comment made by: alexmiller

I really don't like how this looks like bindings, except there's a transducer stuck in it. That seems unlikely to fly from a syntax perspective.

0 votes
by
Reference: https://clojure.atlassian.net/browse/CLJ-1523 (reported by halgari)
...