List of usage examples for org.apache.commons.javaflow.extras Continuations forEach
public @continuable static <T> void forEach(Iterator<T> iterator, ContinuableConsumer<? super T> action)
From source file:org.apache.commons.javaflow.examples.lambdas.LambdasExample.java
private @continuable void executeAll() { // @Continuable method references and @Continuable SAM interfaces are supported ContinuableRunnable r1 = this::lambdaDemo; r1.run();/*from www .j a va 2 s . c om*/ ContinuableRunnable r2 = () -> { System.out.println("ContinuableRunnable by arrow function -- before"); Continuation.suspend(" ** ContinuableRunnable by arrow function"); System.out.println("ContinuableRunnable by arrow function -- after"); }; r2.run(); // Lambda reference MUST have annotated CallSite if SAM interface is not @continuable // Notice that we still MUST create right interface (ContinuableRunnable in this case) @ccs Runnable closure = exec(() -> { System.out.println("Plain Runnable Lambda by arrow function -- before"); Continuation.suspend(" ** Plain Runnable Lambda by arrow function" + ref); System.out.println("Plain Runnable Lambda by arrow function -- after"); }); closure.run(); // We can't use stream.forEach as is, but we can provide good enough helpers // See org.apache.commons.javaflow.examples.lambdas.ContinuableAdapters for // definition of "accept" & "forEach" List<String> listOfStrings = Arrays.asList("A", null, "B", null, "C"); Continuations.forEach(listOfStrings.stream().filter(s -> s != null).map(s -> s + s), accept(this::yieldString1).andThen(this::yieldString2)); }