本文整理了Java中io.reactivex.Flowable.map()
方法的一些代码示例,展示了Flowable.map()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Flowable.map()
方法的具体详情如下:
包路径:io.reactivex.Flowable
类名称: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
@Override
public Publisher<Integer> apply(Flowable<Integer> g) {
return g.map(new Function<Integer, Integer>() {
@Override
public Integer apply(Integer v) throws Exception {
return v + 1;
}
});
}
};
代码示例来源:origin: ReactiveX/RxJava
@Override
public Publisher<Integer> apply(Flowable<Integer> g) {
return g.map(new Function<Integer, Integer>() {
@Override
public Integer apply(Integer v) throws Exception {
return v + 1;
}
});
}
};
代码示例来源:origin: ReactiveX/RxJava
@Override
public Flowable<Integer> apply(final Integer leftValue, Flowable<Integer> rightValues) {
return rightValues.map(new Function<Integer, Integer>() {
@Override
public Integer apply(Integer rightValue) throws Exception {
return add.apply(leftValue, rightValue);
}
});
}
代码示例来源:origin: ReactiveX/RxJava
@Override
public Publisher<String> apply(Flowable<Integer> t1) {
return t1.map(new Function<Integer, String>() {
@Override
public String apply(Integer v) {
return String.valueOf(v);
}
});
}
})
代码示例来源:origin: ReactiveX/RxJava
@Override
public Flowable<String> apply(Flowable<Map<String, String>> f) {
return f.map(new Function<Map<String, String>, String>() {
@Override
public String apply(Map<String, String> map) {
return map.get("firstName");
}
});
}
代码示例来源:origin: ReactiveX/RxJava
@Override
public Flowable<Integer> apply(Integer v) throws Exception {
return Flowable.range(1, 2).map(new Function<Integer, Integer>() {
@Override
public Integer apply(Integer v) throws Exception {
throw new TestException();
}
});
}
})
代码示例来源:origin: ReactiveX/RxJava
@Override
public Flowable<Object> apply(Integer v) throws Exception {
return Flowable.range(1, 2).map(new Function<Integer, Object>() {
@Override
public Object apply(Integer w) throws Exception {
throw new TestException();
}
});
}
})
代码示例来源:origin: ReactiveX/RxJava
@Override
public Flowable<Integer> apply(Integer v) throws Exception {
return Flowable.range(1, 2).map(new Function<Integer, Integer>() {
@Override
public Integer apply(Integer w) throws Exception {
throw new TestException();
}
});
}
}, true)
代码示例来源:origin: ReactiveX/RxJava
@Override
public Flowable<Object> apply(Flowable<Object> f) throws Exception {
return f.map(Functions.identity());
}
});
代码示例来源:origin: ReactiveX/RxJava
@Override
public Object apply(Flowable<Object> f) throws Exception {
return f.map(Functions.identity());
}
}, false, 1, 1, 1);
代码示例来源:origin: ReactiveX/RxJava
@Override
public Publisher<Integer> createPublisher(long elements) {
return
Flowable.range(0, (int)elements).map(Functions.<Integer>identity())
;
}
}
代码示例来源:origin: ReactiveX/RxJava
@Test(expected = NullPointerException.class)
public void mapReturnsNull() {
just1.map(new Function<Integer, Object>() {
@Override
public Object apply(Integer v) {
return null;
}
}).blockingSubscribe();
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void testTake2() {
Flowable<Integer> f = Flowable.just(1, 2, 3, 4, 5);
Iterable<String> it = Arrays.asList("a", "b", "c", "d", "e");
SquareStr squareStr = new SquareStr();
f.map(squareStr).zipWith(it, concat2Strings).take(2).subscribe(printer);
assertEquals(2, squareStr.counter.get());
}
代码示例来源:origin: ReactiveX/RxJava
@SuppressWarnings("unchecked")
@Test
public void source() {
Flowable<Integer> f = Flowable.just(1);
assertSame(f, ((HasUpstreamPublisher<Integer>)f.map(Functions.<Integer>identity())).source());
}
}
代码示例来源:origin: ReactiveX/RxJava
@Test(expected = IllegalArgumentException.class)
public void testMapWithIssue417() {
Flowable.just(1).observeOn(Schedulers.computation())
.map(new Function<Integer, Integer>() {
@Override
public Integer apply(Integer arg0) {
throw new IllegalArgumentException("any error");
}
}).blockingSingle();
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void fusionCrash() {
MulticastProcessor<Integer> mp = Flowable.range(1, 5)
.map(new Function<Integer, Integer>() {
@Override
public Integer apply(Integer v) throws Exception {
throw new IOException();
}
})
.subscribeWith(MulticastProcessor.<Integer>create());
mp.test().assertFailure(IOException.class);
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void synchronousFusedCrash() {
Completable.concat(Flowable.range(1, 2).map(new Function<Integer, Completable>() {
@Override
public Completable apply(Integer v) throws Exception {
throw new TestException();
}
}))
.test()
.assertFailure(TestException.class);
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void fusedCrash() {
Flowable.range(1, 2)
.map(new Function<Integer, Object>() {
@Override
public Object apply(Integer v) throws Exception { throw new TestException(); }
})
.concatMap(Functions.justFunction(Flowable.just(1)))
.test()
.assertFailure(TestException.class);
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void fusedSync() {
TestSubscriber<Integer> ts = SubscriberFusion.newTest(QueueFuseable.ANY);
Flowable.range(1, 5)
.map(Functions.<Integer>identity())
.subscribe(ts);
SubscriberFusion.assertFusion(ts, QueueFuseable.SYNC)
.assertResult(1, 2, 3, 4, 5);
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void testBackpressure2() {
TestSubscriber<Integer> ts = new TestSubscriber<Integer>();
Flowable.range(1, 100000).takeLast(Flowable.bufferSize() * 4)
.observeOn(Schedulers.newThread()).map(newSlowProcessor()).subscribe(ts);
ts.awaitTerminalEvent();
ts.assertNoErrors();
assertEquals(Flowable.bufferSize() * 4, ts.valueCount());
}
内容来源于网络,如有侵权,请联系作者删除!