rx.Observable.takeLast()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(13.8k)|赞(0)|评价(0)|浏览(232)

本文整理了Java中rx.Observable.takeLast()方法的一些代码示例,展示了Observable.takeLast()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Observable.takeLast()方法的具体详情如下:
包路径:rx.Observable
类名称:Observable
方法名:takeLast

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

  1. @Override
  2. public void run() {
  3. Observable.range(1, 10).takeLast(3).subscribe(new Action1<Integer>() {
  4. @Override
  5. public void call(Integer integer) {
  6. log(integer);
  7. }
  8. });
  9. }
  10. });

代码示例来源:origin: com.netflix.rxjava/rxjava-core

  1. /**
  2. * Returns an Observable that emits the last item emitted by the source Observable or notifies observers of
  3. * a {@code NoSuchElementException} if the source Observable is empty.
  4. * <p>
  5. * <img width="640" height="305" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/last.png" alt="">
  6. * <dl>
  7. * <dt><b>Scheduler:</b></dt>
  8. * <dd>{@code last} does not operate by default on a particular {@link Scheduler}.</dd>
  9. * </dl>
  10. *
  11. * @return an Observable that emits the last item from the source Observable or notifies observers of an
  12. * error
  13. * @see <a href="https://github.com/Netflix/RxJava/wiki/Filtering-Observables#last">RxJava wiki: last</a>
  14. * @see "MSDN: Observable.lastAsync"
  15. */
  16. public final Observable<T> last() {
  17. return takeLast(1).single();
  18. }

代码示例来源:origin: com.netflix.rxjava/rxjava-core

  1. /**
  2. * Returns an Observable that emits a single List containing the last {@code count} elements emitted by the
  3. * source Observable.
  4. * <p>
  5. * <img width="640" height="310" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/takeLastBuffer.png" alt="">
  6. * <dl>
  7. * <dt><b>Scheduler:</b></dt>
  8. * <dd>This version of {@code takeLastBuffer} does not operate by default on a particular {@link Scheduler}.</dd>
  9. * </dl>
  10. *
  11. * @param count
  12. * the number of items to emit in the list
  13. * @return an Observable that emits a single list containing the last {@code count} elements emitted by the
  14. * source Observable
  15. * @see <a href="https://github.com/Netflix/RxJava/wiki/Filtering-Observables#takelastbuffer">RxJava wiki: takeLastBuffer</a>
  16. */
  17. public final Observable<List<T>> takeLastBuffer(int count) {
  18. return takeLast(count).toList();
  19. }

代码示例来源:origin: com.netflix.rxjava/rxjava-core

  1. /**
  2. * Returns an Observable that emits a single List containing those items from the source Observable that
  3. * were emitted during a specified window of time before the source Observable completed.
  4. * <p>
  5. * <img width="640" height="310" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/takeLastBuffer.t.png" alt="">
  6. * <dl>
  7. * <dt><b>Scheduler:</b></dt>
  8. * <dd>This version of {@code takeLastBuffer} operates by default on the {@code computation} {@link Scheduler}.</dd>
  9. * </dl>
  10. *
  11. * @param time
  12. * the length of the time window
  13. * @param unit
  14. * the time unit of {@code time}
  15. * @return an Observable that emits a single List containing the items emitted by the source Observable
  16. * during the time window defined by {@code time} before the source Observable completed
  17. * @see <a href="https://github.com/Netflix/RxJava/wiki/Filtering-Observables#takelastbuffer">RxJava wiki: takeLastBuffer</a>
  18. */
  19. public final Observable<List<T>> takeLastBuffer(long time, TimeUnit unit) {
  20. return takeLast(time, unit).toList();
  21. }

代码示例来源:origin: com.netflix.rxjava/rxjava-core

  1. /**
  2. * Returns an Observable that emits only the last item emitted by the source Observable, or a default item
  3. * if the source Observable completes without emitting any items.
  4. * <p>
  5. * <img width="640" height="305" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/lastOrDefault.png" alt="">
  6. * <dl>
  7. * <dt><b>Scheduler:</b></dt>
  8. * <dd>{@code lastOrDefault} does not operate by default on a particular {@link Scheduler}.</dd>
  9. * </dl>
  10. *
  11. * @param defaultValue
  12. * the default item to emit if the source Observable is empty
  13. * @return an Observable that emits only the last item emitted by the source Observable, or a default item
  14. * if the source Observable is empty
  15. * @see <a href="https://github.com/Netflix/RxJava/wiki/Filtering-Observables#lastordefault">RxJava wiki: lastOrDefault</a>
  16. * @see "MSDN: Observable.lastOrDefaultAsync"
  17. */
  18. public final Observable<T> lastOrDefault(T defaultValue) {
  19. return takeLast(1).singleOrDefault(defaultValue);
  20. }

代码示例来源:origin: com.netflix.rxjava/rxjava-core

  1. /**
  2. * Returns an Observable that emits the items from the source Observable that were emitted in a specified
  3. * window of time before the Observable completed.
  4. * <p>
  5. * <img width="640" height="310" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/takeLast.t.png" alt="">
  6. * <dl>
  7. * <dt><b>Scheduler:</b></dt>
  8. * <dd>This version of {@code takeLast} operates by default on the {@code computation} {@link Scheduler}.</dd>
  9. * </dl>
  10. *
  11. * @param time
  12. * the length of the time window
  13. * @param unit
  14. * the time unit of {@code time}
  15. * @return an Observable that emits the items from the source Observable that were emitted in the window of
  16. * time before the Observable completed specified by {@code time}
  17. * @see <a href="https://github.com/Netflix/RxJava/wiki/Filtering-Observables#takelast">RxJava wiki: takeLast</a>
  18. * @see <a href="http://msdn.microsoft.com/en-us/library/hh212114.aspx">MSDN: Observable.TakeLast</a>
  19. */
  20. public final Observable<T> takeLast(long time, TimeUnit unit) {
  21. return takeLast(time, unit, Schedulers.computation());
  22. }

代码示例来源:origin: com.netflix.rxjava/rxjava-core

  1. /**
  2. * Returns an Observable that emits only the last item emitted by the source Observable that satisfies a
  3. * specified condition, or a default item if no such item is emitted by the source Observable.
  4. * <p>
  5. * <img width="640" height="315" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/lastOrDefault.p.png" alt="">
  6. * <dl>
  7. * <dt><b>Scheduler:</b></dt>
  8. * <dd>{@code lastOrDefault} does not operate by default on a particular {@link Scheduler}.</dd>
  9. * </dl>
  10. *
  11. * @param defaultValue
  12. * the default item to emit if the source Observable doesn't emit anything that satisfies the
  13. * specified {@code predicate}
  14. * @param predicate
  15. * the condition any item emitted by the source Observable has to satisfy
  16. * @return an Observable that emits only the last item emitted by the source Observable that satisfies the
  17. * given condition, or a default item if no such item is emitted by the source Observable
  18. * @see <a href="https://github.com/Netflix/RxJava/wiki/Filtering-Observables#lastordefault">RxJava wiki: lastOrDefault</a>
  19. * @see "MSDN: Observable.lastOrDefaultAsync"
  20. */
  21. public final Observable<T> lastOrDefault(T defaultValue, Func1<? super T, Boolean> predicate) {
  22. return filter(predicate).takeLast(1).singleOrDefault(defaultValue);
  23. }

代码示例来源:origin: com.netflix.rxjava/rxjava-core

  1. /**
  2. * Returns an Observable that emits only the last item emitted by the source Observable that satisfies a
  3. * given condition, or notifies of a {@code NoSuchElementException} if no such items are emitted.
  4. * <p>
  5. * <img width="640" height="305" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/last.p.png" alt="">
  6. * <dl>
  7. * <dt><b>Scheduler:</b></dt>
  8. * <dd>{@code last} does not operate by default on a particular {@link Scheduler}.</dd>
  9. * </dl>
  10. *
  11. * @param predicate
  12. * the condition any source emitted item has to satisfy
  13. * @return an Observable that emits only the last item satisfying the given condition from the source, or an
  14. * {@code NoSuchElementException} if no such items are emitted
  15. * @throws IllegalArgumentException
  16. * if no items that match the predicate are emitted by the source Observable
  17. * @see <a href="https://github.com/Netflix/RxJava/wiki/Filtering-Observables#last">RxJava wiki: last</a>
  18. * @see "MSDN: Observable.lastAsync"
  19. */
  20. public final Observable<T> last(Func1<? super T, Boolean> predicate) {
  21. return filter(predicate).takeLast(1).single();
  22. }

代码示例来源:origin: com.netflix.rxjava/rxjava-core

  1. /**
  2. * Returns an Observable that emits a single List containing those items from the source Observable that
  3. * were emitted during a specified window of time before the source Observable completed, where the timing
  4. * information is provided by the given Scheduler.
  5. * <p>
  6. * <img width="640" height="310" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/takeLastBuffer.ts.png" alt="">
  7. * <dl>
  8. * <dt><b>Scheduler:</b></dt>
  9. * <dd>you specify which {@link Scheduler} this operator will use</dd>
  10. * </dl>
  11. *
  12. * @param time
  13. * the length of the time window
  14. * @param unit
  15. * the time unit of {@code time}
  16. * @param scheduler
  17. * the Scheduler that provides the timestamps for the observed items
  18. * @return an Observable that emits a single List containing the items emitted by the source Observable
  19. * during the time window defined by {@code time} before the source Observable completed, where the
  20. * timing information is provided by {@code scheduler}
  21. * @see <a href="https://github.com/Netflix/RxJava/wiki/Filtering-Observables#takelastbuffer">RxJava wiki: takeLastBuffer</a>
  22. */
  23. public final Observable<List<T>> takeLastBuffer(long time, TimeUnit unit, Scheduler scheduler) {
  24. return takeLast(time, unit, scheduler).toList();
  25. }

代码示例来源:origin: com.netflix.rxjava/rxjava-core

  1. /**
  2. * Returns an Observable that emits a single List containing at most {@code count} items from the source
  3. * Observable that were emitted during a specified window of time before the source Observable completed.
  4. * <p>
  5. * <img width="640" height="310" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/takeLastBuffer.tn.png" alt="">
  6. * <dl>
  7. * <dt><b>Scheduler:</b></dt>
  8. * <dd>This version of {@code takeLastBuffer} operates by default on the {@code computation} {@link Scheduler}.</dd>
  9. * </dl>
  10. *
  11. * @param count
  12. * the maximum number of items to emit
  13. * @param time
  14. * the length of the time window
  15. * @param unit
  16. * the time unit of {@code time}
  17. * @return an Observable that emits a single List containing at most {@code count} items emitted by the
  18. * source Observable during the time window defined by {@code time} before the source Observable
  19. * completed
  20. * @see <a href="https://github.com/Netflix/RxJava/wiki/Filtering-Observables#takelastbuffer">RxJava wiki: takeLastBuffer</a>
  21. */
  22. public final Observable<List<T>> takeLastBuffer(int count, long time, TimeUnit unit) {
  23. return takeLast(count, time, unit).toList();
  24. }

代码示例来源:origin: com.netflix.rxjava/rxjava-core

  1. /**
  2. * Returns an Observable that emits at most a specified number of items from the source Observable that were
  3. * emitted in a specified window of time before the Observable completed.
  4. * <p>
  5. * <img width="640" height="310" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/takeLast.tn.png" alt="">
  6. * <dl>
  7. * <dt><b>Scheduler:</b></dt>
  8. * <dd>This version of {@code takeLast} operates by default on the {@code computation} {@link Scheduler}.</dd>
  9. * </dl>
  10. *
  11. * @param count
  12. * the maximum number of items to emit
  13. * @param time
  14. * the length of the time window
  15. * @param unit
  16. * the time unit of {@code time}
  17. * @return an Observable that emits at most {@code count} items from the source Observable that were emitted
  18. * in a specified window of time before the Observable completed
  19. * @see <a href="https://github.com/Netflix/RxJava/wiki/Filtering-Observables#takelast">RxJava wiki: takeLast</a>
  20. * @see <a href="http://msdn.microsoft.com/en-us/library/hh212114.aspx">MSDN: Observable.TakeLast</a>
  21. */
  22. public final Observable<T> takeLast(int count, long time, TimeUnit unit) {
  23. return takeLast(count, time, unit, Schedulers.computation());
  24. }

代码示例来源:origin: com.netflix.rxjava/rxjava-core

  1. /**
  2. * Returns an Observable that emits a single List containing at most {@code count} items from the source
  3. * Observable that were emitted during a specified window of time (on a specified Scheduler) before the
  4. * source Observable completed.
  5. * <p>
  6. * <img width="640" height="310" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/takeLastBuffer.tns.png" alt="">
  7. * <dl>
  8. * <dt><b>Scheduler:</b></dt>
  9. * <dd>you specify which {@link Scheduler} this operator will use</dd>
  10. * </dl>
  11. *
  12. * @param count
  13. * the maximum number of items to emit
  14. * @param time
  15. * the length of the time window
  16. * @param unit
  17. * the time unit of {@code time}
  18. * @param scheduler
  19. * the Scheduler that provides the timestamps for the observed items
  20. * @return an Observable that emits a single List containing at most {@code count} items emitted by the
  21. * source Observable during the time window defined by {@code time} before the source Observable
  22. * completed
  23. * @see <a href="https://github.com/Netflix/RxJava/wiki/Filtering-Observables#takelastbuffer">RxJava wiki: takeLastBuffer</a>
  24. */
  25. public final Observable<List<T>> takeLastBuffer(int count, long time, TimeUnit unit, Scheduler scheduler) {
  26. return takeLast(count, time, unit, scheduler).toList();
  27. }

代码示例来源:origin: com.netflix.rxjava/rxjava-core

  1. return scan(initialValue, accumulator).takeLast(1);

代码示例来源:origin: ladingwu/ApplicationDemo

  1. private void start() {
  2. Observable.from(number)
  3. .filter(new Func1<Integer, Boolean>() {
  4. @Override
  5. public Boolean call(Integer integer) {
  6. return integer%2!=0;
  7. }
  8. })
  9. //取前四个
  10. .take(4)
  11. //取前四个中的后两个
  12. .takeLast(2)
  13. .doOnNext(new Action1<Integer>() {
  14. @Override
  15. public void call(Integer integer) {
  16. mText.append("before onNext()\n");
  17. }
  18. })
  19. .subscribe(new Action1<Integer>() {
  20. @Override
  21. public void call(Integer integer) {
  22. mText.append("onNext()--->"+integer+"\n");
  23. }
  24. });
  25. }
  26. }

代码示例来源:origin: au.gov.amsa.risky/ais

  1. public static void main(String[] args) {
  2. Streams.nmeaFromGzip(new File("/media/an/nmea/2015/NMEA_ITU_20150521.gz"))
  3. .compose(o -> Streams.extract(o)).takeLast(10000).forEach(System.out::println);
  4. }
  5. }

代码示例来源:origin: nurkiewicz/rxjava-book-examples

  1. @Test
  2. public void sample_531() throws Exception {
  3. Observable.range(1, 5).takeLast(2); // [4, 5]
  4. Observable.range(1, 5).skipLast(2); // [1, 2, 3]
  5. }

相关文章

Observable类方法