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 leftCallback
function Mapped over value of
monad
's identity.rightCallback
function "".
_either_
Either | * Returns:
* -- Value of unwrapped resulting value of
flatMap
ped, 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
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 aLeft
creates one from given, else returns given.Parameters:
Name Type Description x
* Returns:
Left -
static toRight(x) → {Right}
-
Returns a
Right
- if not aRight
creates one from given, else returns given.Parameters:
Name Type Description x
* Returns:
Right