use of cyclops.reactive.collections.mutable.ListX in project cyclops by aol.
the class LazyListXTest method testIntercalate2.
@Test
public void testIntercalate2() {
ListX needle = ListX.of(-1, -1, -1);
ListX listOfLists = ListX.of(new ListX[] { ListX.of(1l, 2l, 3l), ListX.of(4l, 5l, 6l), ListX.of(7l, 8l, 9l) });
ListX intercalated = needle.intercalate(listOfLists);
assertThat(intercalated.size(), equalTo(15));
assertThat(intercalated.get(0), equalTo(1l));
assertThat(intercalated.get(1), equalTo(2l));
assertThat(intercalated.get(2), equalTo(3l));
assertThat(intercalated.get(3), equalTo(-1));
assertThat(intercalated.get(4), equalTo(-1));
assertThat(intercalated.get(5), equalTo(-1));
assertThat(intercalated.get(6), equalTo(4l));
assertThat(intercalated.get(7), equalTo(5l));
assertThat(intercalated.get(8), equalTo(6l));
assertThat(intercalated.get(9), equalTo(-1));
assertThat(intercalated.get(10), equalTo(-1));
assertThat(intercalated.get(11), equalTo(-1));
assertThat(intercalated.get(12), equalTo(7l));
assertThat(intercalated.get(13), equalTo(8l));
assertThat(intercalated.get(14), equalTo(9l));
}
use of cyclops.reactive.collections.mutable.ListX in project cyclops by aol.
the class RxTest method asyncFlowableList2.
@Test
public void asyncFlowableList2() {
AtomicBoolean complete = new AtomicBoolean(false);
Flowable<Integer> async = Flowable.fromPublisher(Spouts.reactive(Stream.of(100, 200, 300), Executors.newFixedThreadPool(1))).map(i -> {
Thread.sleep(100);
return i;
}).doOnComplete(() -> complete.set(true));
System.out.println("Initializing!");
ListX<Integer> asyncList = FlowableCollections.listX(async).map(i -> i + 1);
System.out.println("Blocked? " + complete.get());
System.out.println("First value is " + asyncList.get(0));
System.out.println("Blocked? " + complete.get());
}
use of cyclops.reactive.collections.mutable.ListX in project cyclops by aol.
the class RxTest method asyncFlowableList.
@Test
public void asyncFlowableList() {
AtomicBoolean complete = new AtomicBoolean(false);
Flowable<Integer> async = Flowable.fromPublisher(Spouts.reactive(Stream.of(100, 200, 300), Executors.newFixedThreadPool(1))).map(i -> {
Thread.sleep(5000);
return i;
}).doOnComplete(() -> complete.set(true));
ListX<Integer> asyncList = ListX.listX(FlowableReactiveSeq.reactiveSeq(async)).map(i -> i + 1);
System.out.println("Calling materialize!");
asyncList.materialize();
System.out.println("Blocked? " + complete.get());
System.out.println("First value is " + asyncList.get(0));
System.out.println("Blocked? " + complete.get());
}
use of cyclops.reactive.collections.mutable.ListX in project cyclops by aol.
the class FluxesTest method asyncList.
@Test
public void asyncList() {
AtomicBoolean complete = new AtomicBoolean(false);
Flux<Integer> async = Flux.just(1, 2, 3).publishOn(Schedulers.single()).map(i -> {
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
}
return i;
}).doOnComplete(() -> complete.set(true));
ListX<Integer> asyncList = ListX.listX(reactiveSeq(async)).map(i -> i + 1);
System.out.println("Triggering list population!");
asyncList.materialize();
System.out.println("Were we blocked? Has the stream completed? " + complete.get());
System.out.println("First value is " + asyncList.get(0));
System.out.println("Completed? " + complete.get());
}
Aggregations