use of cyclops.futurestream.LazyReact in project cyclops by aol.
the class Tutorial method IO.
@Test
public void IO() {
// stream builder with 50 threads and 50 active futures
LazyReact react = new LazyReact(50, 50).autoOptimizeOn();
react.generateAsync(this::loadNext).takeWhile(this::isActive).map(this::process).peek(this::save).run();
}
use of cyclops.futurestream.LazyReact in project cyclops by aol.
the class RxJavaConversionTest method rxConversionTestSkip.
@Test
public void rxConversionTestSkip() throws InterruptedException, ExecutionException {
List<String> titles = new LazyReact().from(query("Hello, world!").get()).<String>then(url -> getTitle(url)).filter(Objects::nonNull).skip(5).peek(title -> saveTitle(title)).peek(System.out::println).block();
assertThat(titles.size(), is(4));
assertThat(savedCalled, is(4));
}
use of cyclops.futurestream.LazyReact in project cyclops by aol.
the class RxJavaConversionTest method rxConversion.
@Test
public void rxConversion() throws InterruptedException, ExecutionException {
// conversion of non-concurrent RxJava code here :- http://blog.danlew.net/2014/09/22/grokking-rxjava-part-2/
List<String> titles = new LazyReact().fromStreamFutures(Stream.of(query("Hello, world!"))).flatMap(Collection::stream).peek(System.out::println).<String>then(url -> getTitle(url)).filter(Objects::nonNull).limit(5).peek(title -> saveTitle(title)).peek(System.out::println).block();
assertThat(titles.size(), is(5));
assertThat(savedCalled, is(5));
}
use of cyclops.futurestream.LazyReact in project cyclops by aol.
the class AutoMemoizationTest method autoMemoizeOff.
@Test
public void autoMemoizeOff() {
called.set(0);
Map cache = new ConcurrentHashMap<>();
LazyReact react = new LazyReact();
List result = react.of(1, 1, 1, 1).capture(e -> e.printStackTrace()).map(i -> calc(i)).peek(System.out::println).toList();
System.out.println(result);
assertThat(result.size(), equalTo(4));
assertThat(called.get(), greaterThan(3));
}
use of cyclops.futurestream.LazyReact in project cyclops by aol.
the class FastFutureConversionTest method conversion.
@Test
public void conversion() {
CompletableFuture<String> future = CompletableFuture.supplyAsync(() -> "hello");
assertThat(new LazyReact().from(future).peek(System.out::println).then(action -> "result").singleOrElse(null), equalTo("result"));
}
Aggregations