/** * Returns the first item emitted by this {@code BlockingObservable}, or throws * {@code NoSuchElementException} if it emits no items. * * @return the first item emitted by this {@code BlockingObservable} * @throws NoSuchElementException * if this {@code BlockingObservable} emits no items * @see <a href="https://github.com/ReactiveX/RxJava/wiki/Blocking-Observable-Operators#first-and-firstordefault">RxJava Wiki: first()</a> * @see <a href="http://msdn.microsoft.com/en-us/library/hh229177.aspx">MSDN: Observable.First</a> */ public T first() { return blockForSingle(o.first()); }
/** * If this {@code BlockingObservable} completes after emitting a single item, return that item, otherwise * throw a {@code NoSuchElementException}. * <p> * <img width="640" height="315" src="https://github.com/ReactiveX/RxJava/wiki/images/rx-operators/B.single.png" alt=""> * * @return the single item emitted by this {@code BlockingObservable} * @see <a href="https://github.com/ReactiveX/RxJava/wiki/Blocking-Observable-Operators#single-and-singleordefault">RxJava Wiki: single()</a> * @see <a href="http://msdn.microsoft.com/en-us/library/system.reactive.linq.observable.single.aspx">MSDN: Observable.Single</a> */ public T single() { return blockForSingle(o.single()); }
/** * Returns the last item emitted by this {@code BlockingObservable}, or throws * {@code NoSuchElementException} if this {@code BlockingObservable} emits no items. * <p> * <img width="640" height="315" src="https://github.com/ReactiveX/RxJava/wiki/images/rx-operators/B.last.png" alt=""> * * @return the last item emitted by this {@code BlockingObservable} * @throws NoSuchElementException * if this {@code BlockingObservable} emits no items * @see <a href="https://github.com/ReactiveX/RxJava/wiki/Blocking-Observable-Operators#last-and-lastordefault">RxJava Wiki: last()</a> * @see <a href="http://msdn.microsoft.com/en-us/library/system.reactive.linq.observable.last.aspx">MSDN: Observable.Last</a> */ public T last() { return blockForSingle(o.last()); }
/** * Returns the first item emitted by this {@code BlockingObservable} that matches a predicate, or throws * {@code NoSuchElementException} if it emits no such item. * * @param predicate * a predicate function to evaluate items emitted by this {@code BlockingObservable} * @return the first item emitted by this {@code BlockingObservable} that matches the predicate * @throws NoSuchElementException * if this {@code BlockingObservable} emits no such items * @see <a href="https://github.com/ReactiveX/RxJava/wiki/Blocking-Observable-Operators#first-and-firstordefault">RxJava Wiki: first()</a> * @see <a href="http://msdn.microsoft.com/en-us/library/hh229739.aspx">MSDN: Observable.First</a> */ public T first(Func1<? super T, Boolean> predicate) { return blockForSingle(o.first(predicate)); }
/** * If this {@code BlockingObservable} completes after emitting a single item that matches a given predicate, * return that item, otherwise throw a {@code NoSuchElementException}. * <p> * <img width="640" height="315" src="https://github.com/ReactiveX/RxJava/wiki/images/rx-operators/B.single.p.png" alt=""> * * @param predicate * a predicate function to evaluate items emitted by this {@link BlockingObservable} * @return the single item emitted by this {@code BlockingObservable} that matches the predicate * @see <a href="https://github.com/ReactiveX/RxJava/wiki/Blocking-Observable-Operators#single-and-singleordefault">RxJava Wiki: single()</a> * @see <a href="http://msdn.microsoft.com/en-us/library/system.reactive.linq.observable.single.aspx">MSDN: Observable.Single</a> */ public T single(Func1<? super T, Boolean> predicate) { return blockForSingle(o.single(predicate)); }
/** * Returns the last item emitted by this {@code BlockingObservable} that matches a predicate, or throws * {@code NoSuchElementException} if it emits no such items. * <p> * <img width="640" height="315" src="https://github.com/ReactiveX/RxJava/wiki/images/rx-operators/B.last.p.png" alt=""> * * @param predicate * a predicate function to evaluate items emitted by the {@code BlockingObservable} * @return the last item emitted by the {@code BlockingObservable} that matches the predicate * @throws NoSuchElementException * if this {@code BlockingObservable} emits no items * @see <a href="https://github.com/ReactiveX/RxJava/wiki/Blocking-Observable-Operators#last-and-lastordefault">RxJava Wiki: last()</a> * @see <a href="http://msdn.microsoft.com/en-us/library/system.reactive.linq.observable.last.aspx">MSDN: Observable.Last</a> */ public T last(final Func1<? super T, Boolean> predicate) { return blockForSingle(o.last(predicate)); }
/** * Returns the first item emitted by this {@code BlockingObservable} that matches a predicate, or a default * value if it emits no such items. * * @param defaultValue * a default value to return if this {@code BlockingObservable} emits no matching items * @param predicate * a predicate function to evaluate items emitted by this {@code BlockingObservable} * @return the first item emitted by this {@code BlockingObservable} that matches the predicate, or the * default value if this {@code BlockingObservable} emits no matching items * @see <a href="https://github.com/ReactiveX/RxJava/wiki/Blocking-Observable-Operators#first-and-firstordefault">RxJava Wiki: firstOrDefault()</a> * @see <a href="http://msdn.microsoft.com/en-us/library/hh229759.aspx">MSDN: Observable.FirstOrDefault</a> */ public T firstOrDefault(T defaultValue, Func1<? super T, Boolean> predicate) { return blockForSingle(o.filter(predicate).map(Functions.<T>identity()).firstOrDefault(defaultValue)); }
/** * Returns the last item emitted by this {@code BlockingObservable} that matches a predicate, or a default * value if it emits no such items. * <p> * <img width="640" height="315" src="https://github.com/ReactiveX/RxJava/wiki/images/rx-operators/B.lastOrDefault.p.png" alt=""> * * @param defaultValue * a default value to return if this {@code BlockingObservable} emits no matching items * @param predicate * a predicate function to evaluate items emitted by this {@code BlockingObservable} * @return the last item emitted by this {@code BlockingObservable} that matches the predicate, or the * default value if it emits no matching items * @see <a href="https://github.com/ReactiveX/RxJava/wiki/Blocking-Observable-Operators#last-and-lastordefault">RxJava Wiki: lastOrDefault()</a> * @see <a href="http://msdn.microsoft.com/en-us/library/system.reactive.linq.observable.lastordefault.aspx">MSDN: Observable.LastOrDefault</a> */ public T lastOrDefault(T defaultValue, Func1<? super T, Boolean> predicate) { return blockForSingle(o.filter(predicate).map(Functions.<T>identity()).lastOrDefault(defaultValue)); }
/** * Returns the first item emitted by this {@code BlockingObservable}, or a default value if it emits no * items. * * @param defaultValue * a default value to return if this {@code BlockingObservable} emits no items * @return the first item emitted by this {@code BlockingObservable}, or the default value if it emits no * items * @see <a href="https://github.com/ReactiveX/RxJava/wiki/Blocking-Observable-Operators#first-and-firstordefault">RxJava Wiki: firstOrDefault()</a> * @see <a href="http://msdn.microsoft.com/en-us/library/hh229320.aspx">MSDN: Observable.FirstOrDefault</a> */ public T firstOrDefault(T defaultValue) { return blockForSingle(o.map(Functions.<T>identity()).firstOrDefault(defaultValue)); }
/** * If this {@code BlockingObservable} completes after emitting a single item that matches a predicate, * return that item; if it emits more than one such item, throw an {@code IllegalArgumentException}; if it * emits no items, return a default value. * <p> * <img width="640" height="315" src="https://github.com/ReactiveX/RxJava/wiki/images/rx-operators/B.singleOrDefault.p.png" alt=""> * * @param defaultValue * a default value to return if this {@code BlockingObservable} emits no matching items * @param predicate * a predicate function to evaluate items emitted by this {@code BlockingObservable} * @return the single item emitted by the {@code BlockingObservable} that matches the predicate, or the * default value if no such items are emitted * @see <a href="https://github.com/ReactiveX/RxJava/wiki/Blocking-Observable-Operators#single-and-singleordefault">RxJava Wiki: singleOrDefault()</a> * @see <a href="http://msdn.microsoft.com/en-us/library/system.reactive.linq.observable.singleordefault.aspx">MSDN: Observable.SingleOrDefault</a> */ public T singleOrDefault(T defaultValue, Func1<? super T, Boolean> predicate) { return blockForSingle(o.filter(predicate).map(Functions.<T>identity()).singleOrDefault(defaultValue)); }
/** * Returns the last item emitted by this {@code BlockingObservable}, or a default value if it emits no * items. * <p> * <img width="640" height="310" src="https://github.com/ReactiveX/RxJava/wiki/images/rx-operators/B.lastOrDefault.png" alt=""> * * @param defaultValue * a default value to return if this {@code BlockingObservable} emits no items * @return the last item emitted by the {@code BlockingObservable}, or the default value if it emits no * items * @see <a href="https://github.com/ReactiveX/RxJava/wiki/Blocking-Observable-Operators#last-and-lastordefault">RxJava Wiki: lastOrDefault()</a> * @see <a href="http://msdn.microsoft.com/en-us/library/system.reactive.linq.observable.lastordefault.aspx">MSDN: Observable.LastOrDefault</a> */ public T lastOrDefault(T defaultValue) { return blockForSingle(o.map(Functions.<T>identity()).lastOrDefault(defaultValue)); }
/** * If this {@code BlockingObservable} completes after emitting a single item, return that item; if it emits * more than one item, throw an {@code IllegalArgumentException}; if it emits no items, return a default * value. * <p> * <img width="640" height="315" src="https://github.com/ReactiveX/RxJava/wiki/images/rx-operators/B.singleOrDefault.png" alt=""> * * @param defaultValue * a default value to return if this {@code BlockingObservable} emits no items * @return the single item emitted by this {@code BlockingObservable}, or the default value if it emits no * items * @see <a href="https://github.com/ReactiveX/RxJava/wiki/Blocking-Observable-Operators#single-and-singleordefault">RxJava Wiki: singleOrDefault()</a> * @see <a href="http://msdn.microsoft.com/en-us/library/system.reactive.linq.observable.singleordefault.aspx">MSDN: Observable.SingleOrDefault</a> */ public T singleOrDefault(T defaultValue) { return blockForSingle(o.map(Functions.<T>identity()).singleOrDefault(defaultValue)); }