Class Options
java.lang.Object
dmx.fun.Options
Collector facade for
Stream<Option<T>>.
Centralises all Option and NonEmptyList collector factories that operate on
option streams as static methods, mirroring the role of Collectors.
The underlying factories on Option and NonEmptyList are kept for backward
compatibility; this class simply delegates to them.
Usage:
import static dmx.fun.Options.*;
List<String> present = stream.collect(Options.presentToList());
Option<List<String>> seq = stream.collect(Options.sequence());
Option<NonEmptyList<String>> nel = stream.collect(Options.toNonEmptyList());
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionsequence()Returns aCollectorthat reduces aStream<Option<V>>to a singleOption<List<V>>:Option.some(list)if every element is present, orOption.none()if any element is empty.static <T> Collector<T, ?, Option<NonEmptyList<T>>> Returns aCollectorthat accumulates aStream<T>into anOption<NonEmptyList<T>>:Option.some(nel)if the stream is non-empty, orOption.none()if the stream is empty.
-
Method Details
-
presentToList
Returns aCollectorthat collects all present values from aStream<Option<V>>into an unorderedList, discarding empty options.Delegates to
Option.presentValuesToList().- Type Parameters:
V- the value type- Returns:
- a collector producing a
List<V>of present values
-
sequence
Returns aCollectorthat reduces aStream<Option<V>>to a singleOption<List<V>>:Option.some(list)if every element is present, orOption.none()if any element is empty.Delegates to
Option.sequenceCollector().- Type Parameters:
V- the value type- Returns:
- a collector producing
Option<List<V>>
-
toNonEmptyList
Returns aCollectorthat accumulates aStream<T>into anOption<NonEmptyList<T>>:Option.some(nel)if the stream is non-empty, orOption.none()if the stream is empty.Delegates to
NonEmptyList.toNonEmptyList().- Type Parameters:
T- the element type- Returns:
- a collector producing
Option<NonEmptyList<T>>
-