-
Notifications
You must be signed in to change notification settings - Fork 272
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add 'if' operator #96
Comments
Ah, interesting one. Not totally opposed to implementing it, but would love a bit more info. I'd rather not add an abstraction if a simple language construct would do. Could you provide an example where this is more useful than a normal function? Just as a comparison for discussion, here's what I'm thinking: Normal function Stream<int> ifStream(bool shouldRun) => shouldRun
? new Observable<int>.just(42)
: new Observable<int>.empty();
Stream<int> elseStream(bool shouldRun) => shouldRun
? new Observable<int>.just(42)
: new Observable<int>.just(56);
// Normal usage
ifStream(true).listen(print); // prints 42
ifStream(false).listen(print); // prints nothing
// Nice with flatmap
new Observable<bool>.just(false)
.flatMap(elseStream)
.listen(print); // prints 56 If factory var shouldRun = true;
Stream<int> ifStream = new Observable.if(() => shouldRun,
new Observable.just(42));
Stream<int> elseStream = new Observable.if(() => shouldRun,
new Observable.just(42),
new Observable.just(56)); |
Since i haven't heard back for a while, gonna close this out for now. Please write back and re-open if you'd like us to reconsider! |
Creating complex if / else structures is quite hard when your method chain is growing.
RxJS has a nice solution to it:
https://github.com/Reactive-Extensions/RxJS/blob/master/doc/api/core/operators/if.md
It takes a 'condition' method, a 'thenSource' and an 'elseSource' as parameters.
The text was updated successfully, but these errors were encountered: