the "left" item type 'failure'
the "right" item type 'success'
Used by the node REPL to display values.
Map the either: you give a function to apply to the value, a function in case it's a left, a function in case it's a right.
Returns true if this is either is a right and contains the value you give.
Two objects are equal if they represent the same value, regardless of whether they are the same object physically in memory.
"filter" the either. If it was a Left, it stays a Left. If it was a Right and the predicate you pass returns true for its value, return the either unchanged. But if it was a left and the predicate returns false, return a Left with the value returned by the function passed as second parameter.
Either.right<string,number>(-3)
.filter(x => x >= 0, v => "got negative value: " + v);
=> Either.left<string,number>("got negative value: -3")
Get the value contained in this left. NOTE: we know it's there, since this method belongs to Left, not Either.
If this either is a left, return its value, else return the value you give.
If this either is a left, return its value, else throw an exception. You can optionally pass a message that'll be used as the exception message.
If this either is a right, return its value, else return the value you give.
If this either is a right, return its value, else throw an exception. You can optionally pass a message that'll be used as the exception message, or an Error object.
Get a number for that object. Two different values may get the same number, but one value must always get the same number. The formula can impact performance.
Execute a side-effecting function if the either is a left; returns the either.
Execute a side-effecting function if the either is a right; returns the either.
Returns true since this is a Left
Returns false since this is a Left
If this either is a right, applies the function you give to its contents and build a new right either, otherwise return this.
If this either is a left, call the function you give with the left value and return a new either left with the result of the function, else return this.
Handle both branches of the either and return a value (can also be used for side-effects). This is the catamorphism for either.
Either.right<string,number>(5).match({
Left: x => "left " + x,
Right: x => "right " + x
});
=> "right 5"
Has no effect if this Either is a right. If it's a left however, the function you give will be called, receiving as parameter the left contents, and an Either equivalent to the one your function returns will be returned.
Convert to a list. If it's a left, it's the empty list, if it's a right, it's a one-element list with the contents of the either.
Convert this either to an option, conceptually dropping the left (failing) value.
Get a human-friendly string representation of that value.
Convert to a vector. If it's a left, it's the empty vector, if it's a right, it's a one-element vector with the contents of the either.
Transform this value to another value type. Enables fluent-style programming by chaining calls.
Generated using TypeDoc
Represents an Either containing a left value, conceptually tied to a failure. "static methods" available through EitherStatic