FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Not short cutting 'count' Stream collector · Issue #955 · jenetics/jenetics · GitHub

Not short cutting 'count' Stream collector #955

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();
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


    Back | FazBrowse Home | New Git URL