本文整理了Java中rx.Observable.takeLast()
方法的一些代码示例,展示了Observable.takeLast()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Observable.takeLast()
方法的具体详情如下:
包路径:rx.Observable
类名称:Observable
方法名:takeLast
[英]Returns an Observable that emits only the last count items emitted by the source Observable.
Scheduler: This version of takeLast does not operate by default on a particular Scheduler.
[中]
代码示例来源:origin: leeowenowen/rxjava-examples
@Override
public void run() {
Observable.range(1, 10).takeLast(3).subscribe(new Action1<Integer>() {
@Override
public void call(Integer integer) {
log(integer);
}
});
}
});
代码示例来源:origin: com.netflix.rxjava/rxjava-core
/**
* Returns an Observable that emits the last item emitted by the source Observable or notifies observers of
* a {@code NoSuchElementException} if the source Observable is empty.
* <p>
* <img width="640" height="305" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/last.png" alt="">
* <dl>
* <dt><b>Scheduler:</b></dt>
* <dd>{@code last} does not operate by default on a particular {@link Scheduler}.</dd>
* </dl>
*
* @return an Observable that emits the last item from the source Observable or notifies observers of an
* error
* @see <a href="https://github.com/Netflix/RxJava/wiki/Filtering-Observables#last">RxJava wiki: last</a>
* @see "MSDN: Observable.lastAsync"
*/
public final Observable<T> last() {
return takeLast(1).single();
}
代码示例来源:origin: com.netflix.rxjava/rxjava-core
/**
* Returns an Observable that emits a single List containing the last {@code count} elements emitted by the
* source Observable.
* <p>
* <img width="640" height="310" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/takeLastBuffer.png" alt="">
* <dl>
* <dt><b>Scheduler:</b></dt>
* <dd>This version of {@code takeLastBuffer} does not operate by default on a particular {@link Scheduler}.</dd>
* </dl>
*
* @param count
* the number of items to emit in the list
* @return an Observable that emits a single list containing the last {@code count} elements emitted by the
* source Observable
* @see <a href="https://github.com/Netflix/RxJava/wiki/Filtering-Observables#takelastbuffer">RxJava wiki: takeLastBuffer</a>
*/
public final Observable<List<T>> takeLastBuffer(int count) {
return takeLast(count).toList();
}
代码示例来源:origin: com.netflix.rxjava/rxjava-core
/**
* Returns an Observable that emits a single List containing those items from the source Observable that
* were emitted during a specified window of time before the source Observable completed.
* <p>
* <img width="640" height="310" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/takeLastBuffer.t.png" alt="">
* <dl>
* <dt><b>Scheduler:</b></dt>
* <dd>This version of {@code takeLastBuffer} operates by default on the {@code computation} {@link Scheduler}.</dd>
* </dl>
*
* @param time
* the length of the time window
* @param unit
* the time unit of {@code time}
* @return an Observable that emits a single List containing the items emitted by the source Observable
* during the time window defined by {@code time} before the source Observable completed
* @see <a href="https://github.com/Netflix/RxJava/wiki/Filtering-Observables#takelastbuffer">RxJava wiki: takeLastBuffer</a>
*/
public final Observable<List<T>> takeLastBuffer(long time, TimeUnit unit) {
return takeLast(time, unit).toList();
}
代码示例来源:origin: com.netflix.rxjava/rxjava-core
/**
* Returns an Observable that emits only the last item emitted by the source Observable, or a default item
* if the source Observable completes without emitting any items.
* <p>
* <img width="640" height="305" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/lastOrDefault.png" alt="">
* <dl>
* <dt><b>Scheduler:</b></dt>
* <dd>{@code lastOrDefault} does not operate by default on a particular {@link Scheduler}.</dd>
* </dl>
*
* @param defaultValue
* the default item to emit if the source Observable is empty
* @return an Observable that emits only the last item emitted by the source Observable, or a default item
* if the source Observable is empty
* @see <a href="https://github.com/Netflix/RxJava/wiki/Filtering-Observables#lastordefault">RxJava wiki: lastOrDefault</a>
* @see "MSDN: Observable.lastOrDefaultAsync"
*/
public final Observable<T> lastOrDefault(T defaultValue) {
return takeLast(1).singleOrDefault(defaultValue);
}
代码示例来源:origin: com.netflix.rxjava/rxjava-core
/**
* Returns an Observable that emits the items from the source Observable that were emitted in a specified
* window of time before the Observable completed.
* <p>
* <img width="640" height="310" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/takeLast.t.png" alt="">
* <dl>
* <dt><b>Scheduler:</b></dt>
* <dd>This version of {@code takeLast} operates by default on the {@code computation} {@link Scheduler}.</dd>
* </dl>
*
* @param time
* the length of the time window
* @param unit
* the time unit of {@code time}
* @return an Observable that emits the items from the source Observable that were emitted in the window of
* time before the Observable completed specified by {@code time}
* @see <a href="https://github.com/Netflix/RxJava/wiki/Filtering-Observables#takelast">RxJava wiki: takeLast</a>
* @see <a href="http://msdn.microsoft.com/en-us/library/hh212114.aspx">MSDN: Observable.TakeLast</a>
*/
public final Observable<T> takeLast(long time, TimeUnit unit) {
return takeLast(time, unit, Schedulers.computation());
}
代码示例来源:origin: com.netflix.rxjava/rxjava-core
/**
* Returns an Observable that emits only the last item emitted by the source Observable that satisfies a
* specified condition, or a default item if no such item is emitted by the source Observable.
* <p>
* <img width="640" height="315" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/lastOrDefault.p.png" alt="">
* <dl>
* <dt><b>Scheduler:</b></dt>
* <dd>{@code lastOrDefault} does not operate by default on a particular {@link Scheduler}.</dd>
* </dl>
*
* @param defaultValue
* the default item to emit if the source Observable doesn't emit anything that satisfies the
* specified {@code predicate}
* @param predicate
* the condition any item emitted by the source Observable has to satisfy
* @return an Observable that emits only the last item emitted by the source Observable that satisfies the
* given condition, or a default item if no such item is emitted by the source Observable
* @see <a href="https://github.com/Netflix/RxJava/wiki/Filtering-Observables#lastordefault">RxJava wiki: lastOrDefault</a>
* @see "MSDN: Observable.lastOrDefaultAsync"
*/
public final Observable<T> lastOrDefault(T defaultValue, Func1<? super T, Boolean> predicate) {
return filter(predicate).takeLast(1).singleOrDefault(defaultValue);
}
代码示例来源:origin: com.netflix.rxjava/rxjava-core
/**
* Returns an Observable that emits only the last item emitted by the source Observable that satisfies a
* given condition, or notifies of a {@code NoSuchElementException} if no such items are emitted.
* <p>
* <img width="640" height="305" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/last.p.png" alt="">
* <dl>
* <dt><b>Scheduler:</b></dt>
* <dd>{@code last} does not operate by default on a particular {@link Scheduler}.</dd>
* </dl>
*
* @param predicate
* the condition any source emitted item has to satisfy
* @return an Observable that emits only the last item satisfying the given condition from the source, or an
* {@code NoSuchElementException} if no such items are emitted
* @throws IllegalArgumentException
* if no items that match the predicate are emitted by the source Observable
* @see <a href="https://github.com/Netflix/RxJava/wiki/Filtering-Observables#last">RxJava wiki: last</a>
* @see "MSDN: Observable.lastAsync"
*/
public final Observable<T> last(Func1<? super T, Boolean> predicate) {
return filter(predicate).takeLast(1).single();
}
代码示例来源:origin: com.netflix.rxjava/rxjava-core
/**
* Returns an Observable that emits a single List containing those items from the source Observable that
* were emitted during a specified window of time before the source Observable completed, where the timing
* information is provided by the given Scheduler.
* <p>
* <img width="640" height="310" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/takeLastBuffer.ts.png" alt="">
* <dl>
* <dt><b>Scheduler:</b></dt>
* <dd>you specify which {@link Scheduler} this operator will use</dd>
* </dl>
*
* @param time
* the length of the time window
* @param unit
* the time unit of {@code time}
* @param scheduler
* the Scheduler that provides the timestamps for the observed items
* @return an Observable that emits a single List containing the items emitted by the source Observable
* during the time window defined by {@code time} before the source Observable completed, where the
* timing information is provided by {@code scheduler}
* @see <a href="https://github.com/Netflix/RxJava/wiki/Filtering-Observables#takelastbuffer">RxJava wiki: takeLastBuffer</a>
*/
public final Observable<List<T>> takeLastBuffer(long time, TimeUnit unit, Scheduler scheduler) {
return takeLast(time, unit, scheduler).toList();
}
代码示例来源:origin: com.netflix.rxjava/rxjava-core
/**
* Returns an Observable that emits a single List containing at most {@code count} items from the source
* Observable that were emitted during a specified window of time before the source Observable completed.
* <p>
* <img width="640" height="310" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/takeLastBuffer.tn.png" alt="">
* <dl>
* <dt><b>Scheduler:</b></dt>
* <dd>This version of {@code takeLastBuffer} operates by default on the {@code computation} {@link Scheduler}.</dd>
* </dl>
*
* @param count
* the maximum number of items to emit
* @param time
* the length of the time window
* @param unit
* the time unit of {@code time}
* @return an Observable that emits a single List containing at most {@code count} items emitted by the
* source Observable during the time window defined by {@code time} before the source Observable
* completed
* @see <a href="https://github.com/Netflix/RxJava/wiki/Filtering-Observables#takelastbuffer">RxJava wiki: takeLastBuffer</a>
*/
public final Observable<List<T>> takeLastBuffer(int count, long time, TimeUnit unit) {
return takeLast(count, time, unit).toList();
}
代码示例来源:origin: com.netflix.rxjava/rxjava-core
/**
* Returns an Observable that emits at most a specified number of items from the source Observable that were
* emitted in a specified window of time before the Observable completed.
* <p>
* <img width="640" height="310" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/takeLast.tn.png" alt="">
* <dl>
* <dt><b>Scheduler:</b></dt>
* <dd>This version of {@code takeLast} operates by default on the {@code computation} {@link Scheduler}.</dd>
* </dl>
*
* @param count
* the maximum number of items to emit
* @param time
* the length of the time window
* @param unit
* the time unit of {@code time}
* @return an Observable that emits at most {@code count} items from the source Observable that were emitted
* in a specified window of time before the Observable completed
* @see <a href="https://github.com/Netflix/RxJava/wiki/Filtering-Observables#takelast">RxJava wiki: takeLast</a>
* @see <a href="http://msdn.microsoft.com/en-us/library/hh212114.aspx">MSDN: Observable.TakeLast</a>
*/
public final Observable<T> takeLast(int count, long time, TimeUnit unit) {
return takeLast(count, time, unit, Schedulers.computation());
}
代码示例来源:origin: com.netflix.rxjava/rxjava-core
/**
* Returns an Observable that emits a single List containing at most {@code count} items from the source
* Observable that were emitted during a specified window of time (on a specified Scheduler) before the
* source Observable completed.
* <p>
* <img width="640" height="310" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/takeLastBuffer.tns.png" alt="">
* <dl>
* <dt><b>Scheduler:</b></dt>
* <dd>you specify which {@link Scheduler} this operator will use</dd>
* </dl>
*
* @param count
* the maximum number of items to emit
* @param time
* the length of the time window
* @param unit
* the time unit of {@code time}
* @param scheduler
* the Scheduler that provides the timestamps for the observed items
* @return an Observable that emits a single List containing at most {@code count} items emitted by the
* source Observable during the time window defined by {@code time} before the source Observable
* completed
* @see <a href="https://github.com/Netflix/RxJava/wiki/Filtering-Observables#takelastbuffer">RxJava wiki: takeLastBuffer</a>
*/
public final Observable<List<T>> takeLastBuffer(int count, long time, TimeUnit unit, Scheduler scheduler) {
return takeLast(count, time, unit, scheduler).toList();
}
代码示例来源:origin: com.netflix.rxjava/rxjava-core
return scan(initialValue, accumulator).takeLast(1);
代码示例来源:origin: ladingwu/ApplicationDemo
private void start() {
Observable.from(number)
.filter(new Func1<Integer, Boolean>() {
@Override
public Boolean call(Integer integer) {
return integer%2!=0;
}
})
//取前四个
.take(4)
//取前四个中的后两个
.takeLast(2)
.doOnNext(new Action1<Integer>() {
@Override
public void call(Integer integer) {
mText.append("before onNext()\n");
}
})
.subscribe(new Action1<Integer>() {
@Override
public void call(Integer integer) {
mText.append("onNext()--->"+integer+"\n");
}
});
}
}
代码示例来源:origin: au.gov.amsa.risky/ais
public static void main(String[] args) {
Streams.nmeaFromGzip(new File("/media/an/nmea/2015/NMEA_ITU_20150521.gz"))
.compose(o -> Streams.extract(o)).takeLast(10000).forEach(System.out::println);
}
}
代码示例来源:origin: nurkiewicz/rxjava-book-examples
@Test
public void sample_531() throws Exception {
Observable.range(1, 5).takeLast(2); // [4, 5]
Observable.range(1, 5).skipLast(2); // [1, 2, 3]
}
内容来源于网络,如有侵权,请联系作者删除!