[Proposal] Stream.map_reduce/3

42 views
Skip to first unread message

Michał Muskała

unread,
Jul 14, 2017, 3:52:51 AM7/14/17
to elixir-l...@googlegroups.com
I was looking recently into transforming a stream in a one-to-one way that requires maintaining an additional accumulator during the transition. That's an obvious use case for map_reduce with Enum, but with Stream we lack such a function. We have transform/3 that is somewhat equivalent to Enum.flat_map_reduce, that we could use here, but I think I'd prefer something simpler. I'm not 100% sure about the name, though.

Michał.

José Valim

unread,
Jul 14, 2017, 4:06:21 AM7/14/17
to elixir-l...@googlegroups.com
Stream.transform is already optimized for cases where you emit one or zero element, so it is definitely the way to go. And we don't have any _reduce function in Stream exactly because you can't get the accumulator.



José Valim
Skype: jv.ptec
Founder and Director of R&D

On Fri, Jul 14, 2017 at 9:52 AM, Michał Muskała <mic...@muskala.eu> wrote:
I was looking recently into transforming a stream in a one-to-one way that requires maintaining an additional accumulator during the transition. That's an obvious use case for map_reduce with Enum, but with Stream we lack such a function. We have transform/3 that is somewhat equivalent to Enum.flat_map_reduce, that we could use here, but I think I'd prefer something simpler. I'm not 100% sure about the name, though.

Michał.

--
You received this message because you are subscribed to the Google Groups "elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-core+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/2e5eb853-9fd8-4410-a82c-18da0297d4b5%40Spark.
For more options, visit https://groups.google.com/d/optout.

Michał Muskała

unread,
Jul 14, 2017, 4:08:39 AM7/14/17
to elixir-l...@googlegroups.com
Fair enough

Michał.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-co...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/CAGnRm4JWK9JRNarJuo4ZPpB05-n%2B6s5U3k0SHt5rxWbEzbLGKQ%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages