Class Results

java.lang.Object
dmx.fun.Results

@NullMarked public final class Results extends Object
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:
  • Method Details

    • toList

      public static <V,E> Collector<Result<V,E>, ?, Result<List<V>,E>> toList()
      Returns a Collector that accumulates a Stream<Result<V, E>> into a single Result<List<V>, E>, failing on the first Err encountered.

      Delegates to Result.toList().

      Type Parameters:
      V - the value type
      E - the error type
      Returns:
      a collector producing Result<List<V>, E>
    • partitioning

      public static <V,E> Collector<Result<V,E>, ?, Results.Partition<V,E>> partitioning()
      Returns a Collector that partitions a Stream<Result<V, E>> into ok-values and errors.

      Delegates to Result.partitioningBy().

      Type Parameters:
      V - the value type
      E - 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 a Collector that groups stream elements by a key derived from each element.

      Delegates to Result.groupingBy(Function).

      Type Parameters:
      V - the element type
      K - 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,R> Collector<V,?,Map<K,R>> groupingBy(Function<? super V, ? extends K> classifier, Function<? super NonEmptyList<V>, ? extends R> downstream)
      Returns a Collector that groups stream elements by a key derived from each element, then applies a finishing function to each group's NonEmptyList.

      Delegates to Result.groupingBy(Function, Function).

      Type Parameters:
      V - the element type
      K - the key type
      R - the result type of the downstream function
      Parameters:
      classifier - a function mapping each element to a grouping key
      downstream - a function applied to each group's NonEmptyList
      Returns:
      a collector producing a Map<K, R>