Interface Either<L,R>

Type Parameters:
L - Left type
R - Right type
All Known Implementing Classes:
Either.Left, Either.Right

public interface Either<L,R>
The Either type represents a value of one of two possible types (a disjoint union). The data constructors; Left and Right represent the two possible values.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Interface
    Description
    static class 
     
    static class 
     
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Returns if something has been set to the left field.
    boolean
    Returns if something has been set to the right field.
    Retrieve the left value.
    static <L, R> Either<L,R>
    left(L left)
    Creates a new Either with something set to the left value.
    Retrieve the right value.
    static <L, R> Either<L,R>
    right(R right)
    Creates a new Either with something set to the right value.
  • Method Details

    • hasLeft

      boolean hasLeft()
      Returns if something has been set to the left field.

      hasRight() will return false if this method returns true

      Returns:
      true if this is a left value, false if this is a right value
    • hasRight

      boolean hasRight()
      Returns if something has been set to the right field.

      hasLeft() will return false if this method returns true

      Returns:
      true if this is a right value, false if this is a left value
    • left

      @Nullable L left()
      Retrieve the left value.

      May return null even when hasLeft() returns true. Also returns null if this is a right value.

      Returns:
      The set left value
    • right

      @Nullable R right()
      Retrieve the right value.

      May return null even when hasRight() returns true. Also returns null if this is a left value.

      Returns:
      The set right value
    • left

      static <L, R> Either<L,R> left(L left)
      Creates a new Either with something set to the left value.
      Type Parameters:
      L - The type for left
      R - The type for right
      Parameters:
      left - The value that shall be set
      Returns:
      The created Either instance
    • right

      static <L, R> Either<L,R> right(R right)
      Creates a new Either with something set to the right value.
      Type Parameters:
      L - The type for left
      R - The type for right
      Parameters:
      right - The value that shall be set
      Returns:
      The created Either instance