Package io.vavr

Class API.Match<T>

java.lang.Object
io.vavr.API.Match<T>
Type Parameters:
T - type of the object that is matched
Enclosing class:
API

@GwtIncompatible public static final class API.Match<T> extends Object
Scala-like structural pattern matching for Java. Instances are obtained via API.Match(Object).
  • Field Details

    • value

      private final T value
  • Constructor Details

    • Match

      private Match(T value)
  • Method Details

    • of

      @SafeVarargs public final <R> R of(@NonNull API.Match.Case<? extends T,? extends R> @NonNull ... cases)
      Executes the match, created by the factory function API.Match(Object). Throws exceptions when the list of API.Match.Cases is incomplete.
      Type Parameters:
      R - return value type
      Parameters:
      cases - list of cases we execute the match against
      Returns:
      The matched value
      Throws:
      MatchError - if the list of cases was not defined for all possible values of T
    • option

      @SafeVarargs public final <R> Option<R> option(@NonNull API.Match.Case<? extends T,? extends R> @NonNull ... cases)
      Executes the match, created by the factory function API.Match(Object). Returns Option.some(...) if the value was matched and Option.none() otherwise.
      Type Parameters:
      R - return value type
      Parameters:
      cases - list of cases we execute the match against
      Returns:
      Option containing the matched value, or none