dart-lang / sdk

The Dart SDK, including the VM, JS and Wasm compilers, analysis, core libraries, and more.
https://dart.dev
BSD 3-Clause "New" or "Revised" License
10.06k stars 1.56k forks source link

Add more reactive inspired functionality on Stream (and maybe Iterable) #30536

Open lrhn opened 7 years ago

lrhn commented 7 years ago

Currently the simplest way to perform custom transformations of streams is to use the transform method.

someStream.transform(debounce(sec)).map(...).transform(switchLatest(...))

This is long and awkward compared to having the methods on the stream itself:

someStream.debounce(sec).map(...).switchLatest(...)

We should add more Rx inspired operations.

eernstg commented 7 years ago

Those methods would allow for late binding, of course, but if they only have a single implementation (they can still call methods on the Stream using late binding) then we could also express the transformations as functions without loss of expressive power:

switchLatest(map(debounce(someStream, sec), ...), ...)

and of course they could then be called using a BETA style "pipeline" syntax if we add something like the '->' that you've proposed:

someStream -> debounce(sec) -> map(...) -> switchLatest(...)
dotdotcommadot commented 7 years ago

Would definitely be nice if it were 'native' Dart. Meanwhile you might want to have a look at https://github.com/ReactiveX/rxdart.

loic-sharma commented 6 years ago

In C#, the reactive functionality is added through extension methods. For example, here is C#'s Skip extension. This works really well - they've added extension methods for just about everything without cluttering their version of the Iterable type.