Class Either<X,Y>

java.lang.Object
com.supermartijn642.fusion.api.util.Either<X,Y>

public abstract class Either<X,Y> extends Object
Created 09/09/2022 by SuperMartijn642
  • Method Summary

    Modifier and Type
    Method
    Description
    abstract <S> S
    flatMap(Function<X,S> mapLeft, Function<Y,S> mapRight)
    Applies the respective mapper to obtain an object of type Either.
    abstract void
    ifLeft(Consumer<X> consumer)
    Applies the given consumer if this either is a left value.
    abstract void
    ifRight(Consumer<Y> consumer)
    Applies the given consumer if this either is a right value.
    abstract boolean
    Whether the either is a left value or not.
    abstract boolean
    Whether the either is a right value or not.
    abstract X
    Will take this either as a left value.
    static <X, Y> Either<X,Y>
    left(X object)
    Creates a left either instance with the given value.
    abstract X
    leftOrElse(X other)
    Will take this either as a left value.
    abstract X
    Will take this either as a left value.
    Will take this either as a left value.
    <R, S> Either<R,S>
    map(Function<X,R> mapLeft, Function<Y,S> mapRight)
    Applies the respective mapper given whether this either is a left or right value.
    abstract <S> Either<S,Y>
    mapLeft(Function<X,S> mapper)
    Applies the given mapper if this either is a left value.
    abstract <S> Either<X,S>
    mapRight(Function<Y,S> mapper)
    Applies the given mapper if this either is a right value.
    abstract Y
    Will take this either as a right value.
    static <X, Y> Either<X,Y>
    right(Y object)
    Creates a right either instance with the given value.
    abstract Y
    rightOrElse(Y other)
    Will take this either as a right value.
    abstract Y
    Will take this either as a right value.
    Will take this either as a right value.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • left

      public static <X, Y> Either<X,Y> left(X object)
      Creates a left either instance with the given value.
    • right

      public static <X, Y> Either<X,Y> right(Y object)
      Creates a right either instance with the given value.
    • isLeft

      public abstract boolean isLeft()
      Whether the either is a left value or not.
    • isRight

      public abstract boolean isRight()
      Whether the either is a right value or not.
    • left

      public abstract X left()
      Will take this either as a left value.
      Throws:
      NoSuchElementException - if the either is a right value
    • right

      public abstract Y right()
      Will take this either as a right value.
      Throws:
      NoSuchElementException - if the either is a left value
    • leftOrElse

      public abstract X leftOrElse(X other)
      Will take this either as a left value. If this either is a right value, the given alternative will be returned.
    • rightOrElse

      public abstract Y rightOrElse(Y other)
      Will take this either as a right value. If this either is a left value, the given alternative will be returned.
    • leftOrElseGet

      public abstract X leftOrElseGet(Supplier<X> other)
      Will take this either as a left value. If this either is a right value, the given alternative will be resolved and returned.
    • rightOrElseGet

      public abstract Y rightOrElseGet(Supplier<Y> other)
      Will take this either as a right value. If this either is a left value, the given alternative will be resolved and returned.
    • leftOrNull

      public X leftOrNull()
      Will take this either as a left value. If this either is a right value, null will be returned.
    • rightOrNull

      public Y rightOrNull()
      Will take this either as a right value. If this either is a left value, null will be returned.
    • mapLeft

      public abstract <S> Either<S,Y> mapLeft(Function<X,S> mapper)
      Applies the given mapper if this either is a left value.
    • mapRight

      public abstract <S> Either<X,S> mapRight(Function<Y,S> mapper)
      Applies the given mapper if this either is a right value.
    • map

      public <R, S> Either<R,S> map(Function<X,R> mapLeft, Function<Y,S> mapRight)
      Applies the respective mapper given whether this either is a left or right value.
    • flatMap

      public abstract <S> S flatMap(Function<X,S> mapLeft, Function<Y,S> mapRight)
      Applies the respective mapper to obtain an object of type Either.
    • ifLeft

      public abstract void ifLeft(Consumer<X> consumer)
      Applies the given consumer if this either is a left value.
    • ifRight

      public abstract void ifRight(Consumer<Y> consumer)
      Applies the given consumer if this either is a right value.