@Test @Ignore public void shouldZipTwoInfiniteSequences() throws Exception { final LazyFutureStream<Integer> units = LazyFutureStream.iterate(1, n -> n + 1); final LazyFutureStream<Integer> hundreds = LazyFutureStream.iterate(100, n -> n + 100); final Seq<String> zipped = units.zip(hundreds, (n, p) -> n + ": " + p); assertThat( zipped.limit(5).join(), equalTo(LazyFutureStream.of("1: 100", "2: 200", "3: 300", "4: 400", "5: 500").join())); }
@Test public void lazyCollection() { Collection<Integer> col = LazyFutureStream.of(1, 2, 3, 4, 5, 6).map(i -> i + 2).toLazyCollection(); assertThat(col.size(), equalTo(6)); }
@Test public void copy() { LazyFutureStream.of(1, 2, 3, 4, 5, 6) .map(i -> i + 2) .copy(5) .forEach(s -> System.out.println(s.toList())); }
@Test public void shouldZipInfiniteWithFiniteSeq() throws Exception { ThreadPools.setUseCommon(false); final LazyFutureStream<Integer> units = LazyFutureStream.iterate( 1, n -> n + 1); // <-- MEMORY LEAK!- no auto-closing yet, so writes infinetely to it's // async queue final Seq<Integer> hundreds = LazyFutureStream.iterate(100, n -> n + 100).limit(5); final Seq<String> zipped = units.zip(hundreds, (n, p) -> n + ": " + p); assertThat( zipped.limit(5).join(), equalTo(LazyFutureStream.of("1: 100", "2: 200", "3: 300", "4: 400", "5: 500").join())); ThreadPools.setUseCommon(true); }
@Override public Publisher<Long> createPublisher(long elements) { return LazyFutureStream.iterate(0l, i -> i + 1l).sync().limit(elements); }