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!