akka-stream-contrib
akka-stream-contrib copied to clipboard
Add switch/switchMap
the switch
and switchMap
operators, as described in Rx (and also implemented in Monix), are very useful.
For anyone not familiar with it, switch
operates over a stream of streams, always emitting from the latest stream, discarding older streams left behind.
See here for a quick standalone implementation and example.
Sounds interesting, I like the name latest
better than switch
, with Akka Streams terminology it should maybe even be flatMapLatest
(flatMapConcatLatest
is maybe a bit much of a mouthful).
I think it may even be useful enough that it should be a part of Akka Streams core, and implemented as a custom stage rather than composed. WDYT?
@johanandren Sorry for the late response—Google Inbox has been playing tricks on me again.
I agree this would be sufficiently useful to justify including in the core library—I chose to implement it partly because it is a "core" Rx combinator (and partly to see if I can get anywhere using non-trivial composition over the flow DSL, where Monix and FS2 have a small advantage due to abundance of combinators).
If you think this issue should be migrated to the core library, I'd be happy to reimplement and contribute it as a custom stage. Should I open an issue there?
Naming: latest
is a very reasonable alternative name for switch
—Rxrb uses latest
, and both RxPY and RxSwift use switch_latest
and switchLatest
respectively. Regarding switchMap
, I agree thatflatMapLatest
is sufficiently clear—the word "latest" already precludes merging in any meaningful sense, so specifying the concat suffix would be redundant.
Yeah, please open a ticket in core Akka and give it a try, thanks!