Variable Either

Either: {
    isInstance: (<L, R>(value: unknown) => value is Either<L, R>);
    isLeft: (<L, R>() => Mapper<Either<L, R>, boolean>);
    isRight: (<L, R>() => Mapper<Either<L, R>, boolean>);
    left: (<L, R>(value: L) => Either<L, R>);
    leftOr: (<L, R>(fallback: L | Mapper<R, L>) => Mapper<Either<L, R>, L>);
    mapLeft: (<L, R, V>(mapper: Mapper<L, V>) => Mapper<Either<L, R>, Either<V, R>>);
    mapRight: (<L, R, V>(mapper: Mapper<R, V>) => Mapper<Either<L, R>, Either<L, V>>);
    match: (<L, R, V>(onLeft: Mapper<L, V>, onRight: Mapper<R, V>) => Mapper<Either<L, R>, V>);
    right: (<L, R>(value: R) => Either<L, R>);
    rightOr: (<L, R>(fallback: R | Mapper<L, R>) => Mapper<Either<L, R>, R>);
    tapLeft: (<L, R>(callback: Consumer<L>) => Mapper<Either<L, R>, Either<L, R>>);
    tapRight: (<L, R>(callback: Consumer<R>) => Mapper<Either<L, R>, Either<L, R>>);
}

Either-related utilities.

Type declaration

  • isInstance: (<L, R>(value: unknown) => value is Either<L, R>)

    Checks if the provided value is an instance of the Either jonad.

    const value = Either.left(42);
    Either.isInstance(value); // => true
    const value = Either.right(42);
    Either.isInstance(value); // => true
    const value = 42;
    Either.isInstance(value); // => false
      • <L, R>(value): value is Either<L, R>
      • Type Parameters

        • L
        • R

        Parameters

        • value: unknown

          The value to check.

        Returns value is Either<L, R>

        true if the value is an instance of Either, false otherwise.

  • isLeft: (<L, R>() => Mapper<Either<L, R>, boolean>)

    Higher order function returning a function that performs the isLeft method on the provided Either.

    The returned function checks if the value is a Left.

      • <L, R>(): Mapper<Either<L, R>, boolean>
      • Type Parameters

        • L
        • R

        Returns Mapper<Either<L, R>, boolean>

        A function that checks if the provided Either is a Left.

  • isRight: (<L, R>() => Mapper<Either<L, R>, boolean>)

    Higher order function returning a function that performs the isRight method on the provided Either.

    The returned function checks if the value is a Right.

      • <L, R>(): Mapper<Either<L, R>, boolean>
      • Type Parameters

        • L
        • R

        Returns Mapper<Either<L, R>, boolean>

        A function that checks if the provided Either is a Right.

  • left: (<L, R>(value: L) => Either<L, R>)

    Creates a new Left instance.

    const value = Either.left(42);
    value.isLeft(); // => true
      • <L, R>(value): Either<L, R>
      • Type Parameters

        • L
        • R

        Parameters

        • value: L

          The value to wrap.

        Returns Either<L, R>

        A new Left instance.

  • leftOr: (<L, R>(fallback: L | Mapper<R, L>) => Mapper<Either<L, R>, L>)

    Higher order function returning a function that performs the leftOr method on the provided Either.

    The returned function returns the value if it is a Left, otherwise returns a default value.

      • <L, R>(fallback): Mapper<Either<L, R>, L>
      • Type Parameters

        • L
        • R

        Parameters

        • fallback: L | Mapper<R, L>

          The default value (as-is or produced from a callback) to return if the value is a Right.

        Returns Mapper<Either<L, R>, L>

        A function that returns the value if it is a Left, otherwise the default value.

  • mapLeft: (<L, R, V>(mapper: Mapper<L, V>) => Mapper<Either<L, R>, Either<V, R>>)

    Higher order function returning a function that performs the mapLeft method on the provided Either.

    The returned function maps the value if it is a Left, otherwise returns the value as-is.

  • mapRight: (<L, R, V>(mapper: Mapper<R, V>) => Mapper<Either<L, R>, Either<L, V>>)

    Higher order function returning a function that performs the mapRight method on the provided Either.

    The returned function maps the value if it is a Right, otherwise returns the value as-is.

  • match: (<L, R, V>(onLeft: Mapper<L, V>, onRight: Mapper<R, V>) => Mapper<Either<L, R>, V>)

    Higher order function returning a function that performs the match method on the provided Either.

    The returned funct)ion matches the jonad by calling the appropriate callback based on the value type.

      • <L, R, V>(onLeft, onRight): Mapper<Either<L, R>, V>
      • Type Parameters

        • L
        • R
        • V

        Parameters

        • onLeft: Mapper<L, V>

          If the value is a Left, this callback is called with the value.

        • onRight: Mapper<R, V>

          If the value is a Right, this callback is called with the value.

        Returns Mapper<Either<L, R>, V>

  • right: (<L, R>(value: R) => Either<L, R>)

    Creates a new Right instance.

    const value = Either.right(42);
    value.isRight(); // => true
      • <L, R>(value): Either<L, R>
      • Type Parameters

        • L
        • R

        Parameters

        • value: R

          The error to wrap.

        Returns Either<L, R>

        A new Right instance.

  • rightOr: (<L, R>(fallback: R | Mapper<L, R>) => Mapper<Either<L, R>, R>)

    Higher order function returning a function that performs the rightOr method on the provided Either.

    The returned function returns the value if it is a Left, otherwise returns a default value asynchronously.

      • <L, R>(fallback): Mapper<Either<L, R>, R>
      • Type Parameters

        • L
        • R

        Parameters

        • fallback: R | Mapper<L, R>

          The default value (as-is or produced from a callback) to return if the value is a Right.

        Returns Mapper<Either<L, R>, R>

        A function that returns the value if it is a Left, otherwise the default value.

  • tapLeft: (<L, R>(callback: Consumer<L>) => Mapper<Either<L, R>, Either<L, R>>)

    Higher order function returning a function that performs the tapLeft method on the provided Either.

    The returned function applies a function to the value if it is a Left, returning itself.

      • <L, R>(callback): Mapper<Either<L, R>, Either<L, R>>
      • Type Parameters

        • L
        • R

        Parameters

        • callback: Consumer<L>

          The function to apply to the value if it is a Left.

        Returns Mapper<Either<L, R>, Either<L, R>>

        A function that applies a function to the value if it is a Left, returning itself.

  • tapRight: (<L, R>(callback: Consumer<R>) => Mapper<Either<L, R>, Either<L, R>>)

    Higher order function returning a function that performs the tapRight method on the provided Either.

    The returned function applies a function to the value if it is a Right, returning itself.

      • <L, R>(callback): Mapper<Either<L, R>, Either<L, R>>
      • Type Parameters

        • L
        • R

        Parameters

        • callback: Consumer<R>

          The function to apply to the value if it is a Right.

        Returns Mapper<Either<L, R>, Either<L, R>>

        A function that applies a function to the value if it is a Right, returning itself.