Class Results
java.lang.Object
dmx.fun.Results
Collector facade for
Stream<Result<V, E>>.
Centralises all Result collector factories as static methods, mirroring the role
of Collectors. The underlying factories on Result are kept
for backward compatibility; this class simply delegates to them.
Usage:
import dmx.fun.Results;
Result<List<Integer>, String> r = stream.collect(Results.toList());
Results.Partition<Integer, String> p = stream.collect(Results.partitioning());
Map<String, NonEmptyList<Item>> m = stream.collect(Results.groupingBy(Item::category));
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordTransparent alias forResult.Partitionso callers can useResults.Partitionwithout importingResultdirectly. -
Method Summary
Modifier and TypeMethodDescriptionstatic <V,K> Collector <V, ?, Map<K, NonEmptyList<V>>> groupingBy(Function<? super V, ? extends K> classifier) Returns aCollectorthat groups stream elements by a key derived from each element.groupingBy(Function<? super V, ? extends K> classifier, Function<? super NonEmptyList<V>, ? extends R> downstream) Returns aCollectorthat groups stream elements by a key derived from each element, then applies a finishing function to each group'sNonEmptyList.static <V,E> Collector <Result<V, E>, ?, Results.Partition<V, E>> Returns aCollectorthat partitions aStream<Result<V, E>>into ok-values and errors.toList()Returns aCollectorthat accumulates aStream<Result<V, E>>into a singleResult<List<V>, E>, failing on the firstErrencountered.
-
Method Details
-
toList
Returns aCollectorthat accumulates aStream<Result<V, E>>into a singleResult<List<V>, E>, failing on the firstErrencountered.Delegates to
Result.toList().- Type Parameters:
V- the value typeE- the error type- Returns:
- a collector producing
Result<List<V>, E>
-
partitioning
Returns aCollectorthat partitions aStream<Result<V, E>>into ok-values and errors.Delegates to
Result.partitioningBy().- Type Parameters:
V- the value typeE- the error type- Returns:
- a collector producing a
Results.Partition
-
groupingBy
public static <V,K> Collector<V, ?, Map<K, NonEmptyList<V>>> groupingBy(Function<? super V, ? extends K> classifier) Returns aCollectorthat groups stream elements by a key derived from each element.Delegates to
Result.groupingBy(Function).- Type Parameters:
V- the element typeK- the key type- Parameters:
classifier- a function mapping each element to a grouping key- Returns:
- a collector producing a
Map<K, NonEmptyList<V>>
-
groupingBy
public static <V,K, Collector<V,R> ?, groupingByMap<K, R>> (Function<? super V, ? extends K> classifier, Function<? super NonEmptyList<V>, ? extends R> downstream) Returns aCollectorthat groups stream elements by a key derived from each element, then applies a finishing function to each group'sNonEmptyList.Delegates to
Result.groupingBy(Function, Function).- Type Parameters:
V- the element typeK- the key typeR- the result type of the downstream function- Parameters:
classifier- a function mapping each element to a grouping keydownstream- a function applied to each group'sNonEmptyList- Returns:
- a collector producing a
Map<K, R>
-