From 5e907fcdd62e7ec421fce89c6ab2c746566206cb Mon Sep 17 00:00:00 2001 From: Grzegorz Piwowarek Date: Wed, 9 Oct 2024 20:54:45 +0200 Subject: [PATCH] Use greedy Integrator for MoreGatherers.sample() --- .../com/pivovarit/gatherers/MoreGatherers.java | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/pivovarit/gatherers/MoreGatherers.java b/src/main/java/com/pivovarit/gatherers/MoreGatherers.java index a4bc934..c0359a9 100644 --- a/src/main/java/com/pivovarit/gatherers/MoreGatherers.java +++ b/src/main/java/com/pivovarit/gatherers/MoreGatherers.java @@ -9,6 +9,7 @@ import java.util.function.BiFunction; import java.util.function.Function; import java.util.stream.Gatherer; +import java.util.stream.Gatherer.Integrator; import java.util.stream.Stream; import static java.util.stream.Gatherer.Integrator.ofGreedy; @@ -27,13 +28,13 @@ private MoreGatherers() { ? noop() : Gatherer.ofSequential( () -> new AtomicLong(), - (state, element, downstream) -> { - if (state.getAndIncrement() % n == 0) { - downstream.push(element); - } - return true; - } - ); + Integrator.ofGreedy((state, element, downstream) -> { + if (state.getAndIncrement() % n == 0) { + downstream.push(element); + } + return true; + } + )); } public static Gatherer distinctBy(Function keyExtractor) {