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

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

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

Observable.takeFirst介绍

[英]Returns an Observable that emits only the very first item emitted by the source Observable that satisfies a specified condition.

Scheduler: takeFirst does not operate by default on a particular Scheduler.
[中]返回仅发射源可观测项发出的第一个满足指定条件的可观测项。
调度程序:默认情况下,takeFirst不会在特定调度程序上运行。

代码示例

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

@Override
 public void run() {
  Observable.range(1, 10).takeFirst(new Func1<Integer, Boolean>() {
   @Override
   public Boolean call(Integer integer) {
    return integer % 2 == 0;
   }
  }).subscribe(new Action1<Integer>() {
   @Override
   public void call(Integer integer) {
    log(integer);
   }
  });
 }
});

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

/**
 * Returns an Observable that emits only the very first item emitted by the source Observable that satisfies
 * a specified condition, or notifies of an {@code NoSuchElementException} if no such items are emitted.
 * <p>
 * <img width="640" height="310" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/firstN.png" alt="">
 * <dl>
 *  <dt><b>Scheduler:</b></dt>
 *  <dd>{@code first} does not operate by default on a particular {@link Scheduler}.</dd>
 * </dl>
 * 
 * @param predicate
 *            the condition that an item emitted by the source Observable has to satisfy
 * @return an Observable that emits only the very first item emitted by the source Observable that satisfies
 *         the {@code predicate}, or raises an {@code NoSuchElementException} if no such items are emitted
 * @see <a href="https://github.com/Netflix/RxJava/wiki/Filtering-Observables#first-and-takefirst">RxJava wiki: takeFirst</a>
 * @see "MSDN: Observable.firstAsync"
 */
public final Observable<T> first(Func1<? super T, Boolean> predicate) {
  return takeFirst(predicate).single();
}

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

/**
 * Returns an Observable that emits only the very first item emitted by the source Observable that satisfies
 * a specified condition, or a default item if the source Observable emits no such items.
 * <p>
 * <img width="640" height="310" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/firstOrDefaultN.png" alt="">
 * <dl>
 *  <dt><b>Scheduler:</b></dt>
 *  <dd>{@code firstOrDefault} does not operate by default on a particular {@link Scheduler}.</dd>
 * </dl>
 * 
 * @param predicate
 *            the condition any item emitted by the source Observable has to satisfy
 * @param defaultValue
 *            the default item to emit if the source Observable doesn't emit anything that satisfies the
 *            {@code predicate}
 * @return an Observable that emits only the very first item emitted by the source Observable that satisfies
 *         the {@code predicate}, or a default item if the source Observable emits no such items
 * @see <a href="https://github.com/Netflix/RxJava/wiki/Filtering-Observables#firstordefault">RxJava wiki: firstOrDefault</a>
 * @see "MSDN: Observable.firstOrDefaultAsync"
 */
public final Observable<T> firstOrDefault(T defaultValue, Func1<? super T, Boolean> predicate) {
  return takeFirst(predicate).singleOrDefault(defaultValue);
}

代码示例来源:origin: chiclaim/AndroidRxJavaSample

.takeFirst(new Func1<String, Boolean>() {
  @Override
  public Boolean call(String s) {

相关文章

Observable类方法