diff --git a/README.md b/README.md index 4aa6620..b5c03a4 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -[![Maven Central](https://img.shields.io/maven-central/v/net.tascalate.javaflow/net.tascalate.javaflow.extras.svg)](https://search.maven.org/artifact/net.tascalate.javaflow/net.tascalate.javaflow.extras/2.3.0/jar) [![GitHub release](https://img.shields.io/github/release/vsilaev/tascalate-javaflow-extras.svg)](https://github.com/vsilaev/tascalate-javaflow-extras/releases/tag/2.3.0) [![license](https://img.shields.io/github/license/vsilaev/tascalate-javaflow-extras.svg)](https://github.com/vsilaev/tascalate-javaflow-extras/blob/master/LICENSE) +[![Maven Central](https://img.shields.io/maven-central/v/net.tascalate.javaflow/net.tascalate.javaflow.extras.svg)](https://search.maven.org/artifact/net.tascalate.javaflow/net.tascalate.javaflow.extras/2.3.1/jar) [![GitHub release](https://img.shields.io/github/release/vsilaev/tascalate-javaflow-extras.svg)](https://github.com/vsilaev/tascalate-javaflow-extras/releases/tag/2.3.1) [![license](https://img.shields.io/github/license/vsilaev/tascalate-javaflow-extras.svg)](https://github.com/vsilaev/tascalate-javaflow-extras/blob/master/LICENSE) # Tascalate JavaFlow Extras Continuations / CoRoutines for Java 8+. This library is an add-on to [Tascalate Javaflow](https://github.com/vsilaev/tascalate-javaflow) continuations library. It provides suspendable version of java.util.Stream, java.util.Iterator, java.util.function.* and helper classes to work with continuations. diff --git a/pom.xml b/pom.xml index 10fd499..a7f1543 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ net.tascalate.javaflow net.tascalate.javaflow.extras - 2.3.0 + 2.3.1 jar diff --git a/src/main/java/net/tascalate/javaflow/Continuations.java b/src/main/java/net/tascalate/javaflow/Continuations.java index 2721611..e7e656b 100644 --- a/src/main/java/net/tascalate/javaflow/Continuations.java +++ b/src/main/java/net/tascalate/javaflow/Continuations.java @@ -287,7 +287,7 @@ public static void forEachReply(SuspendableRunnable coroutine, Function void forEach$(Continuation coroutine, SuspendableConsumer action) { + public static @continuable void forEach$(Continuation coroutine, SuspendableConsumer action) { forEach$(coroutine, false, action); } @@ -301,7 +301,7 @@ public static void forEachReply(SuspendableRunnable coroutine, Function void forEach$(Continuation coroutine, boolean useCurrentValue, SuspendableConsumer action) { + public static @continuable void forEach$(Continuation coroutine, boolean useCurrentValue, SuspendableConsumer action) { try (CloseableIterator iter = iteratorOf(coroutine, useCurrentValue)) { forEach$(iter, action); } @@ -315,7 +315,7 @@ public static void forEachReply(SuspendableRunnable coroutine, Function void forEach$(SuspendableRunnable coroutine, SuspendableConsumer action) { + public static @continuable void forEach$(SuspendableRunnable coroutine, SuspendableConsumer action) { forEach$(create(coroutine), false, action); } @@ -336,7 +336,7 @@ public static void forEachReply(SuspendableRunnable coroutine, Function void forEachReply$(Continuation coroutine, SuspendableFunction action) { + public static @continuable void forEachReply$(Continuation coroutine, SuspendableFunction action) { forEachReply$(coroutine, false, action); } @@ -358,7 +358,7 @@ public static void forEachReply(SuspendableRunnable coroutine, Function void forEachReply$(Continuation coroutine, boolean useCurrentValue, SuspendableFunction action) { + public static @continuable void forEachReply$(Continuation coroutine, boolean useCurrentValue, SuspendableFunction action) { Continuation cc = coroutine; try { Object param = null; @@ -394,7 +394,7 @@ public static void forEachReply(SuspendableRunnable coroutine, Function void forEachReply$(SuspendableRunnable coroutine, SuspendableFunction action) { + public static @continuable void forEachReply$(SuspendableRunnable coroutine, SuspendableFunction action) { forEachReply$(create(coroutine), action); } @@ -408,7 +408,7 @@ public static void forEachReply(SuspendableRunnable coroutine, Function void forEach$(Stream stream, SuspendableConsumer action) { + public static @continuable void forEach$(Stream stream, SuspendableConsumer action) { forEach$(stream.iterator(), action); } @@ -422,7 +422,7 @@ public static void forEachReply(SuspendableRunnable coroutine, Function void forEach$(Iterable iterable, SuspendableConsumer action) { + public static @continuable void forEach$(Iterable iterable, SuspendableConsumer action) { Iterator iter = iterable.iterator(); try (CloseableIterator closeable = asCloseable(iter)) { forEach$(iter, action); @@ -439,7 +439,7 @@ public static void forEachReply(SuspendableRunnable coroutine, Function void forEach$(Iterator iterator, SuspendableConsumer action) { + private static @continuable void forEach$(Iterator iterator, SuspendableConsumer action) { while (iterator.hasNext()) { action.accept(iterator.next()); } diff --git a/src/main/java/net/tascalate/javaflow/SuspendableStream.java b/src/main/java/net/tascalate/javaflow/SuspendableStream.java index 15a078a..37635a9 100644 --- a/src/main/java/net/tascalate/javaflow/SuspendableStream.java +++ b/src/main/java/net/tascalate/javaflow/SuspendableStream.java @@ -138,20 +138,22 @@ public Option produce() { public static SuspendableStream iterate(T seed, UnaryOperator f) { return new SuspendableStream<>(new RootProducer() { - Option current = Option.none(); + Option current = null; @Override public Option produce() { - return current.exists() ? current.map(f) : Option.some(seed); + current = null == current ? Option.some(seed) : current.map(f); + return current; } }); } public static SuspendableStream iterate$(T seed, SuspendableUnaryOperator f) { return new SuspendableStream<>(new RootProducer() { - Option current = Option.none(); + Option current = null; @Override public Option produce() { - return current.exists() ? current.map$(f) : Option.some(seed); + current = null == current ? Option.some(seed) : current.map$(f); + return current; } }); }