-
Notifications
You must be signed in to change notification settings - Fork 162
Closed
Description
The Stream.count() terminal Stream operation might shortcut the evaluation of the Stream, which might not be desirable in certain conditions.
@Override
protected int crossover(final MSeq<G> that, final MSeq<G> other) {
final int length = min(that.length(), other.length());
return (int)indexes(RandomRegistry.random(), length, _swapProbability)
.peek(i -> that.swap(i, other))
.count();
}A Collector<T, ?, Long> collector should avoid this kind of problem.
@Override
protected int crossover(final MSeq<G> that, final MSeq<G> other) {
final int length = min(that.length(), other.length());
return indexes(RandomRegistry.random(), length, _swapProbability)
.collect(count(i -> that.swap(i, other)))
.intValue();
}