either

Contains Either constructs (Right, Left, either etc.) and associated operations. Created by elyde on 12/10/2016.

Classes

Left

Right

Methods

static either(leftCallback, rightCallback, _either_) → {*}

Calls matching callback on incoming Either's type; If is a Left (after mapping identity func on it) then calls left-callback and unwraps result else calls right-callback and does the same. Think of it like a functional ternary statement (lol).

Parameters:
Name Type Description
leftCallback function

Mapped over value of monad's identity.

rightCallback function

"".

_either_ Either | *
Returns:
* -
  • Value of unwrapped resulting value of flatMapped, passed-in callback's on passed in monad.
Example
expect(
         either(() => 404, () => 200, compose(right, right, right, right)(true))
       ).toEqual(undefined);

static isLeft(x) → {boolean}

Checks for instance of Left constructor.

Parameters:
Name Type Description
x *
Returns:
boolean

static isRight(x) → {boolean}

Checks for instance of Right constructor.

Parameters:
Name Type Description
x *
Returns:
boolean

static left(x) → {Left}

Returns a new Left

Parameters:
Name Type Description
x *
Returns:
Left

static right(x) → {Right}

Returns a Right.

Parameters:
Name Type Description
x *
Returns:
Right

static toEither(x) → {Left|Right}

Converts given to an either (Right|Left)

Parameters:
Name Type Description
x *
Returns:
Left | Right

static toLeft(x) → {Left}

Returns a Left - if not a Left creates one from given, else returns given.

Parameters:
Name Type Description
x *
Returns:
Left

static toRight(x) → {Right}

Returns a Right - if not a Right creates one from given, else returns given.

Parameters:
Name Type Description
x *
Returns:
Right