io.reactivex.Observable.to()方法的使用及代码示例

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

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

Observable.to介绍

[英]Calls the specified converter function during assembly time and returns its resulting value.

This allows fluent conversion to any other type. Scheduler: to does not operate by default on a particular Scheduler.
[中]在汇编期间调用指定的转换器函数并返回其结果值。
这允许流畅地转换为任何其他类型。调度程序:默认情况下,不在特定调度程序上运行。

代码示例

代码示例来源:origin: ReactiveX/RxJava

@Test(expected = NullPointerException.class)
public void toNull() {
  just1.to(null);
}

代码示例来源:origin: square/sqlbrite

@CheckResult @NonNull
private QueryObservable createQuery(DatabaseQuery query) {
 if (transactions.get() != null) {
  throw new IllegalStateException("Cannot create observable query in transaction. "
    + "Use query() for a query inside a transaction.");
 }
 return triggers //
   .filter(query) // DatabaseQuery filters triggers to on tables we care about.
   .map(query) // DatabaseQuery maps to itself to save an allocation.
   .startWith(query) //
   .observeOn(scheduler) //
   .compose(queryTransformer) // Apply the user's query transformer.
   .doOnSubscribe(ensureNotInTransaction)
   .to(QUERY_OBSERVABLE);
}

代码示例来源:origin: ReactiveX/RxJava

@Test
public void testExtend() {
  final TestObserver<Object> to = new TestObserver<Object>();
  final Object value = new Object();
  Object returned = Observable.just(value).to(new Function<Observable<Object>, Object>() {
    @Override
    public Object apply(Observable<Object> onSubscribe) {
        onSubscribe.subscribe(to);
        to.assertNoErrors();
        to.assertComplete();
        to.assertValue(value);
        return to.values().get(0);
      }
  });
  assertSame(returned, value);
}

代码示例来源:origin: square/sqlbrite

.to(QUERY_OBSERVABLE);

代码示例来源:origin: ReactiveX/RxJava

@Test
public void syncIterable() {
  Observable.fromIterable(Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10))
  .to(ObserverFusion.<Integer>test(QueueFuseable.ANY, false))
  .assertOf(ObserverFusion.<Integer>assertFusionMode(QueueFuseable.SYNC))
  .assertValues(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
  .assertNoErrors()
  .assertComplete();
}

代码示例来源:origin: ReactiveX/RxJava

@Test
  public void syncIterableHidden() {
    Observable.fromIterable(Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10))
    .hide()
    .to(ObserverFusion.<Integer>test(QueueFuseable.ANY, false))
    .assertOf(ObserverFusion.<Integer>assertNotFuseable())
    .assertOf(ObserverFusion.<Integer>assertFusionMode(QueueFuseable.NONE))
    .assertValues(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
    .assertNoErrors()
    .assertComplete();
  }
}

代码示例来源:origin: ReactiveX/RxJava

@Test
public void syncRange() {
  Observable.range(1, 10)
  .to(ObserverFusion.<Integer>test(QueueFuseable.ANY, false))
  .assertOf(ObserverFusion.<Integer>assertFusionMode(QueueFuseable.SYNC))
  .assertValues(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
  .assertNoErrors()
  .assertComplete();
}

代码示例来源:origin: ReactiveX/RxJava

@Test
public void syncArray() {
  Observable.fromArray(new Integer[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 })
  .to(ObserverFusion.<Integer>test(QueueFuseable.ANY, false))
  .assertOf(ObserverFusion.<Integer>assertFusionMode(QueueFuseable.SYNC))
  .assertValues(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
  .assertNoErrors()
  .assertComplete();
}

代码示例来源:origin: ReactiveX/RxJava

@Test
public void syncRangeHidden() {
  Observable.range(1, 10).hide()
  .to(ObserverFusion.<Integer>test(QueueFuseable.ANY, false))
  .assertOf(ObserverFusion.<Integer>assertNotFuseable())
  .assertOf(ObserverFusion.<Integer>assertFusionMode(QueueFuseable.NONE))
  .assertValues(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
  .assertNoErrors()
  .assertComplete();
}

代码示例来源:origin: ReactiveX/RxJava

@Test
public void syncArrayHidden() {
  Observable.fromArray(new Integer[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 })
  .hide()
  .to(ObserverFusion.<Integer>test(QueueFuseable.ANY, false))
  .assertOf(ObserverFusion.<Integer>assertNotFuseable())
  .assertOf(ObserverFusion.<Integer>assertFusionMode(QueueFuseable.NONE))
  .assertValues(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
  .assertNoErrors()
  .assertComplete();
}

代码示例来源:origin: akarnokd/RxJava2Jdk8Interop

@Test
public void toStream() {
  List<Integer> list = Observable.just(1, 2, 3, 4, 5)
  .to(ObservableInterop.toStream())
  .collect(Collectors.toList());
  Assert.assertEquals(Arrays.asList(1, 2, 3, 4, 5), list);
}

代码示例来源:origin: akarnokd/RxJava2Jdk8Interop

@Test
public void single() {
  TestHelper.assertFuture(1, Observable.just(1)
      .to(ObservableInterop.single())
  );
}

代码示例来源:origin: akarnokd/RxJava2Jdk8Interop

@Test
public void firstElementEmpty() {
  Assert.assertFalse(Observable.empty()
  .to(ObservableInterop.firstElement()).isPresent());
}

代码示例来源:origin: akarnokd/RxJava2Jdk8Interop

@Test
public void lastElement() {
  Assert.assertEquals((Integer)5, Observable.range(1, 5)
  .to(ObservableInterop.lastElement()).get());
}

代码示例来源:origin: akarnokd/RxJava2Jdk8Interop

@Test
public void firstElement() {
  Assert.assertEquals((Integer)1, Observable.range(1, 5)
  .to(ObservableInterop.firstElement()).get());
}

代码示例来源:origin: akarnokd/RxJava2Jdk8Interop

@Test
public void lastElementEmpty() {
  Assert.assertFalse(Observable.empty()
  .to(ObservableInterop.lastElement()).isPresent());
}

代码示例来源:origin: akarnokd/RxJava2Jdk8Interop

@Test
public void first() {
  TestHelper.assertFuture(1, Observable.range(1, 5)
      .to(ObservableInterop.first())
  );
}

代码示例来源:origin: akarnokd/RxJava2Jdk8Interop

@Test(expected = NoSuchElementException.class)
public void lastEmpty() {
  TestHelper.assertFuture(null, Observable.empty()
      .to(ObservableInterop.last())
  );
}

代码示例来源:origin: akarnokd/RxJava2Jdk8Interop

@Test(expected = IllegalArgumentException.class)
public void singleLonger() {
  TestHelper.assertFuture(null, Observable.range(1, 5)
      .to(ObservableInterop.single())
  );
}

代码示例来源:origin: akarnokd/RxJava2Jdk8Interop

@Test(expected = NoSuchElementException.class)
public void firstEmpty() {
  TestHelper.assertFuture(null, Observable.empty()
      .to(ObservableInterop.first())
  );
}

相关文章

Observable类方法