diff --git a/src/main/java/com/pivovarit/collectors/CompletionStrategy.java b/src/main/java/com/pivovarit/collectors/CompletionStrategy.java index bd74edcd..d7d6af54 100644 --- a/src/main/java/com/pivovarit/collectors/CompletionStrategy.java +++ b/src/main/java/com/pivovarit/collectors/CompletionStrategy.java @@ -6,13 +6,31 @@ import java.util.stream.Stream; import java.util.stream.StreamSupport; -interface CompletionStrategy extends Function>, Stream> { +sealed interface CompletionStrategy + extends Function>, Stream> + permits CompletionStrategy.Unordered, CompletionStrategy.Ordered { static CompletionStrategy unordered() { - return futures -> StreamSupport.stream(new CompletionOrderSpliterator<>(futures), false); + return new Unordered<>(); } static CompletionStrategy ordered() { - return futures -> futures.stream().map(CompletableFuture::join); + return new Ordered<>(); + } + + final class Unordered implements CompletionStrategy { + + @Override + public Stream apply(List> futures) { + return StreamSupport.stream(new CompletionOrderSpliterator<>(futures), false); + } + } + + final class Ordered implements CompletionStrategy { + + @Override + public Stream apply(List> futures) { + return futures.stream().map(CompletableFuture::join); + } } }