Contains Either constructs (Right, Left, either etc.) and associated operations.
Created by elyde on 12/10/2016.
Classes
Methods
-
static either(leftCallback, rightCallback, _either_) → {*}
-
Calls matching callback on incoming
Either's type; If is aLeft(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 leftCallbackfunction Mapped over value of
monad's identity.rightCallbackfunction "".
_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); - Value of unwrapped resulting value of
-
static isLeft(x) → {boolean}
-
Checks for instance of
Leftconstructor.Parameters:
Name Type Description x* Returns:
boolean -
static isRight(x) → {boolean}
-
Checks for instance of
Rightconstructor.Parameters:
Name Type Description x* Returns:
boolean -
static left(x) → {Left}
-
Returns a new
LeftParameters:
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 aLeftcreates one from given, else returns given.Parameters:
Name Type Description x* Returns:
Left -
static toRight(x) → {Right}
-
Returns a
Right- if not aRightcreates one from given, else returns given.Parameters:
Name Type Description x* Returns:
Right