use of cyclops.control.Trampoline in project cyclops by aol.
the class TrampolineTest method coroutine.
@Test
public void coroutine() {
results = new ArrayList();
Iterator<String> it = Arrays.asList("hello", "world", "take").iterator();
val coroutine = new Trampoline[1];
coroutine[0] = Trampoline.more(() -> it.hasNext() ? print(it.next(), coroutine[0]) : Trampoline.done(0));
withCoroutine(coroutine[0]);
assertThat(results, equalTo(Arrays.asList(0, "hello", 1, "world", 2, "take", 3, 4)));
}
Aggregations