Skip to content

Please add toOptional and onlyElement collectors #188

@trtrmitya

Description

@trtrmitya

Hello,

Please add two more collectors:

  • onlyElement
    if streams has exactly one element, return it; otherwise throw an exception

  • toOptional
    return Optional.empty is stream is empty, Optional.of(elem) if streams has exactly one element, and throw an exception otherwise

Names taken from Guava's MoreCollectors.

Alternative good choice for naming is single / singleO.

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions