Search in sources :

Example 1 with Trampoline

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)));
}
Also used : lombok.val(lombok.val) Eval(cyclops.control.Eval) Trampoline(cyclops.control.Trampoline) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Aggregations

Eval (cyclops.control.Eval)1 Trampoline (cyclops.control.Trampoline)1 ArrayList (java.util.ArrayList)1 lombok.val (lombok.val)1 Test (org.junit.Test)1