DefaultIfEmpty
emit items from the source Observable, or a default item if the source Observable emits nothing
See Also
Language-Specific Information
RxGroovy defaultIfEmpty switchIfEmpty
There is also a new operator in RxGroovy 1.1 called switchIfEmpty
that, rather than emitting a backup value if the source Observable terminates without having emitted any items, it emits the emissions from a backup Observable.
RxJava 1․x defaultIfEmpty switchIfEmpty
There is also a new operator in RxJava 1.1 called switchIfEmpty
that, rather than emitting a backup value if the source Observable terminates without having emitted any items, it emits the emissions from a backup Observable.
Sample Code
Observable.empty().defaultIfEmpty(10).subscribe( val -> System.out.println("next: " + val), err -> System.err.println(err) , () -> System.out.println("completed") );
next: 10 completed
RxJava 2․x defaultIfEmpty switchIfEmpty
Sample Code
Flowable.empty().defaultIfEmpty(10).subscribe( val -> System.out.println("next: " + val), err -> System.err.println(err) , () -> System.out.println("completed") );
next: 10 completed
RxJS defaultIfEmpty
RxPHP defaultIfEmpty
© ReactiveX contributors
Licensed under the Apache License 2.0.
http://reactivex.io/documentation/operators/defaultifempty.html