io.reactivex.Flowable.map()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(5.8k)|赞(0)|评价(0)|浏览(288)

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

Flowable.map介绍

[英]Returns a Flowable that applies a specified function to each item emitted by the source Publisher and emits the results of these function applications.

Backpressure: The operator doesn't interfere with backpressure which is determined by the source Publisher's backpressure behavior. Scheduler: map does not operate by default on a particular Scheduler.
[中]返回一个可流动函数,该函数将指定函数应用于源发布服务器发出的每个项,并发出这些函数应用程序的结果。
背压:操作员不会干扰由源发布者的背压行为确定的背压。计划程序:默认情况下,映射不会在特定计划程序上运行。

代码示例

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

  1. @Override
  2. public Publisher<Integer> apply(Flowable<Integer> g) {
  3. return g.map(new Function<Integer, Integer>() {
  4. @Override
  5. public Integer apply(Integer v) throws Exception {
  6. return v + 1;
  7. }
  8. });
  9. }
  10. };

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

  1. @Override
  2. public Publisher<Integer> apply(Flowable<Integer> g) {
  3. return g.map(new Function<Integer, Integer>() {
  4. @Override
  5. public Integer apply(Integer v) throws Exception {
  6. return v + 1;
  7. }
  8. });
  9. }
  10. };

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

  1. @Override
  2. public Flowable<Integer> apply(final Integer leftValue, Flowable<Integer> rightValues) {
  3. return rightValues.map(new Function<Integer, Integer>() {
  4. @Override
  5. public Integer apply(Integer rightValue) throws Exception {
  6. return add.apply(leftValue, rightValue);
  7. }
  8. });
  9. }

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

  1. @Override
  2. public Publisher<String> apply(Flowable<Integer> t1) {
  3. return t1.map(new Function<Integer, String>() {
  4. @Override
  5. public String apply(Integer v) {
  6. return String.valueOf(v);
  7. }
  8. });
  9. }
  10. })

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

  1. @Override
  2. public Flowable<String> apply(Flowable<Map<String, String>> f) {
  3. return f.map(new Function<Map<String, String>, String>() {
  4. @Override
  5. public String apply(Map<String, String> map) {
  6. return map.get("firstName");
  7. }
  8. });
  9. }

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

  1. @Override
  2. public Flowable<Integer> apply(Integer v) throws Exception {
  3. return Flowable.range(1, 2).map(new Function<Integer, Integer>() {
  4. @Override
  5. public Integer apply(Integer v) throws Exception {
  6. throw new TestException();
  7. }
  8. });
  9. }
  10. })

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

  1. @Override
  2. public Flowable<Object> apply(Integer v) throws Exception {
  3. return Flowable.range(1, 2).map(new Function<Integer, Object>() {
  4. @Override
  5. public Object apply(Integer w) throws Exception {
  6. throw new TestException();
  7. }
  8. });
  9. }
  10. })

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

  1. @Override
  2. public Flowable<Integer> apply(Integer v) throws Exception {
  3. return Flowable.range(1, 2).map(new Function<Integer, Integer>() {
  4. @Override
  5. public Integer apply(Integer w) throws Exception {
  6. throw new TestException();
  7. }
  8. });
  9. }
  10. }, true)

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

  1. @Override
  2. public Flowable<Object> apply(Flowable<Object> f) throws Exception {
  3. return f.map(Functions.identity());
  4. }
  5. });

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

  1. @Override
  2. public Object apply(Flowable<Object> f) throws Exception {
  3. return f.map(Functions.identity());
  4. }
  5. }, false, 1, 1, 1);

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

  1. @Override
  2. public Publisher<Integer> createPublisher(long elements) {
  3. return
  4. Flowable.range(0, (int)elements).map(Functions.<Integer>identity())
  5. ;
  6. }
  7. }

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

  1. @Test(expected = NullPointerException.class)
  2. public void mapReturnsNull() {
  3. just1.map(new Function<Integer, Object>() {
  4. @Override
  5. public Object apply(Integer v) {
  6. return null;
  7. }
  8. }).blockingSubscribe();
  9. }

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

  1. @Test
  2. public void testTake2() {
  3. Flowable<Integer> f = Flowable.just(1, 2, 3, 4, 5);
  4. Iterable<String> it = Arrays.asList("a", "b", "c", "d", "e");
  5. SquareStr squareStr = new SquareStr();
  6. f.map(squareStr).zipWith(it, concat2Strings).take(2).subscribe(printer);
  7. assertEquals(2, squareStr.counter.get());
  8. }

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

  1. @SuppressWarnings("unchecked")
  2. @Test
  3. public void source() {
  4. Flowable<Integer> f = Flowable.just(1);
  5. assertSame(f, ((HasUpstreamPublisher<Integer>)f.map(Functions.<Integer>identity())).source());
  6. }
  7. }

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

  1. @Test(expected = IllegalArgumentException.class)
  2. public void testMapWithIssue417() {
  3. Flowable.just(1).observeOn(Schedulers.computation())
  4. .map(new Function<Integer, Integer>() {
  5. @Override
  6. public Integer apply(Integer arg0) {
  7. throw new IllegalArgumentException("any error");
  8. }
  9. }).blockingSingle();
  10. }

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

  1. @Test
  2. public void fusionCrash() {
  3. MulticastProcessor<Integer> mp = Flowable.range(1, 5)
  4. .map(new Function<Integer, Integer>() {
  5. @Override
  6. public Integer apply(Integer v) throws Exception {
  7. throw new IOException();
  8. }
  9. })
  10. .subscribeWith(MulticastProcessor.<Integer>create());
  11. mp.test().assertFailure(IOException.class);
  12. }

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

  1. @Test
  2. public void synchronousFusedCrash() {
  3. Completable.concat(Flowable.range(1, 2).map(new Function<Integer, Completable>() {
  4. @Override
  5. public Completable apply(Integer v) throws Exception {
  6. throw new TestException();
  7. }
  8. }))
  9. .test()
  10. .assertFailure(TestException.class);
  11. }

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

  1. @Test
  2. public void fusedCrash() {
  3. Flowable.range(1, 2)
  4. .map(new Function<Integer, Object>() {
  5. @Override
  6. public Object apply(Integer v) throws Exception { throw new TestException(); }
  7. })
  8. .concatMap(Functions.justFunction(Flowable.just(1)))
  9. .test()
  10. .assertFailure(TestException.class);
  11. }

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

  1. @Test
  2. public void fusedSync() {
  3. TestSubscriber<Integer> ts = SubscriberFusion.newTest(QueueFuseable.ANY);
  4. Flowable.range(1, 5)
  5. .map(Functions.<Integer>identity())
  6. .subscribe(ts);
  7. SubscriberFusion.assertFusion(ts, QueueFuseable.SYNC)
  8. .assertResult(1, 2, 3, 4, 5);
  9. }

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

  1. @Test
  2. public void testBackpressure2() {
  3. TestSubscriber<Integer> ts = new TestSubscriber<Integer>();
  4. Flowable.range(1, 100000).takeLast(Flowable.bufferSize() * 4)
  5. .observeOn(Schedulers.newThread()).map(newSlowProcessor()).subscribe(ts);
  6. ts.awaitTerminalEvent();
  7. ts.assertNoErrors();
  8. assertEquals(Flowable.bufferSize() * 4, ts.valueCount());
  9. }

相关文章

Flowable类方法