Skip to content

Commit

Permalink
Use greedy Integrator for MoreGatherers.sample() (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
pivovarit authored Oct 9, 2024
1 parent 31afeee commit 94de294
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/main/java/com/pivovarit/gatherers/MoreGatherers.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 <T, U> Gatherer<T, ?, T> distinctBy(Function<? super T, ? extends U> keyExtractor) {
Expand Down

0 comments on commit 94de294

Please sign in to comment.