Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Either<L1, R1>

A data structure that represents Success/Failure & optional types

Type parameters

  • L1

    Represents Left case that can be used to depict failures.

  • R1

    Represents Right case that can be used to depict success.

Hierarchy

Index

Accessors

asOption

Methods

Abstract biChain

  • biChain<L2, R2>(LL: function, RR: function): Either<L2, R2>
  • Like Either.map it uses the left function to chain over object of Left type and the right function to chain over an object of Right type.

    Type parameters

    • L2

    • R2

    Parameters

    • LL: function
        • Parameters

          • l: L1

          Returns Either<L2, R2>

    • RR: function
        • Parameters

          • r: R1

          Returns Either<L2, R2>

    Returns Either<L2, R2>

biMap

  • biMap<L2, R2>(LL: function, RR: function): Either<L2, R2>
  • It uses the left function to chain over object of Left type and the right function to chain over an object of Right type.

    Type parameters

    • L2

    • R2

    Parameters

    • LL: function
        • (l: L1): L2
        • Parameters

          • l: L1

          Returns L2

    • RR: function
        • (r: R1): R2
        • Parameters

          • r: R1

          Returns R2

    Returns Either<L2, R2>

chain

  • chain<R2>(ab: function): Either<L1, R2>

chainL

  • chainL<L2>(ab: function): Either<L2, R1>

chainR

  • chainR<R2>(ab: function): Either<L1, R2>

Abstract fold

  • fold<S>(seed: S, LL: function, RR: function): S
  • Reduces an Either to a value of type S by providing a seed value

    Type parameters

    • S

    Parameters

    • seed: S
    • LL: function
        • (l: L1, s: S): S
        • Parameters

          • l: L1
          • s: S

          Returns S

    • RR: function
        • (r: R1, s: S): S
        • Parameters

          • r: R1
          • s: S

          Returns S

    Returns S

Abstract getLeftOrElse

  • getLeftOrElse(left: L1): L1
  • Gets the left value if available or else returns the provided default value

    Parameters

    • left: L1

    Returns L1

Abstract getRightOrElse

  • getRightOrElse(right: R1): R1
  • Gets the right value if available or else returns the provided default value

    Parameters

    • right: R1

    Returns R1

map

  • map<R2>(ab: function): Either<L1, R2>

mapL

  • mapL<L2>(ab: function): Either<L2, R1>
  • Transforms the left value

    Type parameters

    • L2

    Parameters

    • ab: function
        • (r: L1): L2
        • Parameters

          • r: L1

          Returns L2

    Returns Either<L2, R1>

mapR

  • mapR<R2>(ab: function): Either<L1, R2>
  • Transforms the right value

    Type parameters

    • R2

    Parameters

    • ab: function
        • (r: R1): R2
        • Parameters

          • r: R1

          Returns R2

    Returns Either<L1, R2>

Abstract reduce

  • reduce<S>(LL: function, RR: function): S
  • Reduces an Either to a value of type S by providing a seed value

    Type parameters

    • S

    Parameters

    • LL: function
        • (l: L1): S
        • Parameters

          • l: L1

          Returns S

    • RR: function
        • (r: R1): S
        • Parameters

          • r: R1

          Returns S

    Returns S

Static fromOption

Static isLeft

  • isLeft<L1, R1>(either: Either<L1, R1>): boolean

Static isRight

  • isRight<L1, R1>(either: Either<L1, R1>): boolean

Static left

  • left<L>(left: L): Either<L, never>

Static right

  • right<R>(right: R): Either<never, R>

Static try

  • try<E1, A1>(cb: function): Either<E1, A1>
  • Creates a new Either type from a function that could fail with an error.

    Type parameters

    • E1

    • A1

    Parameters

    • cb: function
        • (): A1
        • Returns A1

    Returns Either<E1, A1>

Generated using TypeDoc