/** * Apply a transformation to all values of the underlying stream. */ public <U> FluentFutureStream<U> map(Function<T, U> function) { return FluentFutureStream.of( CompletableFutureUtil.map(completableFuture(), function)); }
/** * Apply a transformation to all values of the underlying stream. */ public <U> FluentFutureStream<U> map(Function<T, U> function) { return FluentFutureStream.of( CompletableFutureUtil.map(completableFuture(), function)); }
/** * Apply a transformation to all values of the underlying stream. */ public <U> FluentFutureStream<U> map(Function<T, U> function) { return FluentFutureStream.of( CompletableFutureUtil.map(completableFuture(), function)); }
@Test public void mapShouldReturnEmptyStreamWhenGivenAnEmptyStream() { CompletableFuture<Stream<Integer>> futurOfInteger = CompletableFuture.completedFuture(Stream.of()); assertThat( CompletableFutureUtil.map(futurOfInteger, integer -> integer * 2) .join() .collect(Guavate.toImmutableList())) .isEmpty(); }
@Test void mapShouldMapOnStreamInsideACompletableFuturOfStream() { CompletableFuture<Stream<Integer>> futurOfInteger = CompletableFuture.completedFuture(Stream.of(1, 2, 3)); assertThat( CompletableFutureUtil.map(futurOfInteger, integer -> integer * 2) .join() .collect(Guavate.toImmutableList())) .containsExactly(2, 4, 6); }
@Test void mapShouldReturnEmptyStreamWhenGivenAnEmptyStream() { CompletableFuture<Stream<Integer>> futurOfInteger = CompletableFuture.completedFuture(Stream.of()); assertThat( CompletableFutureUtil.map(futurOfInteger, integer -> integer * 2) .join() .collect(Guavate.toImmutableList())) .isEmpty(); }
@Test public void mapShouldMapOnStreamInsideACompletableFuturOfStream() { CompletableFuture<Stream<Integer>> futurOfInteger = CompletableFuture.completedFuture(Stream.of(1, 2, 3)); assertThat( CompletableFutureUtil.map(futurOfInteger, integer -> integer * 2) .join() .collect(Guavate.toImmutableList())) .containsExactly(2, 4, 6); }