@telostat/prelude - v0.7.0
    Preparing search index...

    Interface Either<L, R>

    interface Either<L, R> {
        alt(other: Either<L, R>): Either<L, R>;
        altLazy(other: () => Either<L, R>): Either<L, R>;
        ap<L2, R2>(other: Either<L2, (value: R) => R2>): Either<L | L2, R2>;
        bimap<L2, R2>(f: (value: L) => L2, g: (value: R) => R2): Either<L2, R2>;
        caseOf<T>(patterns: EitherPatterns<L, R, T>): T;
        chain<L2, R2>(f: (value: R) => Either<L2, R2>): Either<L | L2, R2>;
        chainLeft<L2, R2>(f: (value: L) => Either<L2, R2>): Either<L2, R | R2>;
        equals(other: Either<L, R>): boolean;
        extend<R2>(f: (value: Either<L, R>) => R2): Either<L, R2>;
        extract(): L | R;
        "fantasy-land/alt"(other: Either<L, R>): Either<L, R>;
        "fantasy-land/ap"<R2>(other: Either<L, (value: R) => R2>): Either<L, R2>;
        "fantasy-land/bimap"<L2, R2>(
            f: (value: L) => L2,
            g: (value: R) => R2,
        ): Either<L2, R2>;
        "fantasy-land/chain"<L2, R2>(
            f: (value: R) => Either<L2, R2>,
        ): Either<L | L2, R2>;
        "fantasy-land/equals"(other: Either<L, R>): boolean;
        "fantasy-land/extend"<R2>(f: (value: Either<L, R>) => R2): Either<L, R2>;
        "fantasy-land/map"<R2>(f: (value: R) => R2): Either<L, R2>;
        "fantasy-land/reduce"<T>(
            reducer: (accumulator: T, value: R) => T,
            initialValue: T,
        ): T;
        ifLeft(effect: (value: L) => any): this;
        ifRight(effect: (value: R) => any): this;
        inspect(): string;
        isLeft(): this is Either<L, never>;
        isRight(): this is Either<never, R>;
        join<L2, R2>(this: Either<L, Either<L2, R2>>): Either<L | L2, R2>;
        leftOrDefault(defaultValue: L): L;
        leftOrDefaultLazy(getDefaultValue: () => L): L;
        leftToMaybe(): Maybe<L>;
        map<R2>(f: (value: R) => R2): Either<L, R2>;
        mapLeft<L2>(f: (value: L) => L2): Either<L2, R>;
        orDefault(defaultValue: R): R;
        orDefaultLazy(getDefaultValue: () => R): R;
        reduce<T>(reducer: (accumulator: T, value: R) => T, initialValue: T): T;
        swap(): Either<R, L>;
        toJSON(): L | R;
        toMaybe(): Maybe<R>;
        toString(): string;
        unsafeCoerce(): R;
    }

    Type Parameters

    • L
    • R
    Index

    Methods

    • Returns the first Right between this and another Either or the Left in the argument if both this and the argument are Left

      Parameters

      Returns Either<L, R>

    • Lazy version of alt

      Parameters

      Returns Either<L, R>

    • Applies a Right function over a Right value. Returns Left if either this or the function are Left

      Type Parameters

      • L2
      • R2

      Parameters

      Returns Either<L | L2, R2>

    • Given two functions, maps the value inside this using the first if this is Left or using the second one if this is Right. If both functions return the same type consider using Either#either instead

      Type Parameters

      • L2
      • R2

      Parameters

      • f: (value: L) => L2
      • g: (value: R) => R2

      Returns Either<L2, R2>

    • Structural pattern matching for Either in the form of a function

      Type Parameters

      • T

      Parameters

      Returns T

    • Transforms this with a function that returns an Either. Useful for chaining many computations that may fail

      Type Parameters

      • L2
      • R2

      Parameters

      Returns Either<L | L2, R2>

    • The same as Either#chain but executes the transformation function only if the value is Left. Useful for recovering from errors

      Type Parameters

      • L2
      • R2

      Parameters

      Returns Either<L2, R | R2>

    • Compares this to another Either, returns false if the constructors or the values inside are different, e.g. Right(5).equals(Left(5)) is false

      Parameters

      Returns boolean

    • Returns this if it's a Left, otherwise it returns the result of applying the function argument to this and wrapping it in a Right

      Type Parameters

      • R2

      Parameters

      Returns Either<L, R2>

    • Extracts the value out of this

      Returns L | R

    • Type Parameters

      • R2

      Parameters

      Returns Either<L, R2>

    • Type Parameters

      • L2
      • R2

      Parameters

      • f: (value: L) => L2
      • g: (value: R) => R2

      Returns Either<L2, R2>

    • Parameters

      Returns boolean

    • Type Parameters

      • R2

      Parameters

      • f: (value: R) => R2

      Returns Either<L, R2>

    • Type Parameters

      • T

      Parameters

      • reducer: (accumulator: T, value: R) => T
      • initialValue: T

      Returns T

    • Runs an effect if this is Left, returns this to make chaining other methods possible

      Parameters

      • effect: (value: L) => any

      Returns this

    • Runs an effect if this is Right, returns this to make chaining other methods possible

      Parameters

      • effect: (value: R) => any

      Returns this

    • Returns string

    • Returns true if this is Left, otherwise it returns false

      Returns this is Either<L, never>

    • Returns true if this is Right, otherwise it returns false

      Returns this is Either<never, R>

    • Returns the value inside this if it's Left or a default value if this is Right

      Parameters

      • defaultValue: L

      Returns L

    • Lazy version of leftOrDefault. Takes a function that returns the default value, that function will be called only if this is Right

      Parameters

      • getDefaultValue: () => L

      Returns L

    • Constructs a Just with the value of this if it's Left or a Nothing if this is Right

      Returns Maybe<L>

    • Maps the Right value of this, acts like an identity if this is Left

      Type Parameters

      • R2

      Parameters

      • f: (value: R) => R2

      Returns Either<L, R2>

    • Maps the Left value of this, acts like an identity if this is Right

      Type Parameters

      • L2

      Parameters

      • f: (value: L) => L2

      Returns Either<L2, R>

    • Returns the value inside this if it's Right or a default value if this is Left

      Parameters

      • defaultValue: R

      Returns R

    • Lazy version of orDefault. Takes a function that returns the default value, that function will be called only if this is Left

      Parameters

      • getDefaultValue: () => R

      Returns R

    • Takes a reducer and an initial value and returns the initial value if this is Left or the result of applying the function to the initial value and the value inside this

      Type Parameters

      • T

      Parameters

      • reducer: (accumulator: T, value: R) => T
      • initialValue: T

      Returns T

    • Returns Right if this is Left and vice versa

      Returns Either<R, L>

    • Returns L | R

    • Constructs a Just with the value of this if it's Right or a Nothing if this is Left

      Returns Maybe<R>

    • Returns string

    • Returns the value inside this if it's a Right or either throws the value or a generic exception depending on whether the value is an Error

      Returns R