The Result monad represents some result in different states - Initial, Pending, Success and Failure.
npm install @lonli-lokli/ts-resultResult Monad - monad represents some result in different states - Initial, Pending, Success and Failure.
In my mental model, REST requests have one of four states:
* We haven't asked yet.
* We've asked, but we haven't got a response yet.
* We got a response, but it was an error.
* We got a response, and it was the data we wanted.
That is the purpose of this library - allow clean usage over this states.
Better explanation your can read in the artice How Elm Slays a UI Antipattern
typescript
import { Result, success } from "@lonli-lokli/ts-result";class UserNotFoundError extends Error {
name: "UserNotFoundError";
}
type User = { email: string; password: string };
function getUser(id: number): Result {
return success({ email: "test@gmail.com", password: "test" });
}
// Result
const user = getUser(1).map(({ email }) => email);
`API
chain
- merge
- mergeWithConfig
- mergeInOne
- mergeInMany
- initial
- pending
- failure
- success
- from
- fromPromise
- fromTry
- fromMaybe
- fromEither
- fromNullable
- isResult
- Result#isInitial
- Result#isPending
- Result#isFailure
- Result#isSuccess
- Result#equal
- Result#or
- Result#join
- Result#map
- Result#mapSuccess
- Result#mapFailure
- Result#asyncMap
- Result#apply
- Result#asyncApply
- Result#chain
- Result#asyncChain
- Result#toEither
- Result#toMaybe
- Result#toNullable
- Result#toUndefined
- Result#unwrap
- Result#unwrapOr
- Result#unwrapOrElse
- Result#fold
- Result#filter
- Result#filtermap
- Result#tap
- Result#tapFailure
- Result#recover
- Result#recoverWith
- Result#zip
- Result#zipWith
- Result#biMap
- Helpers####
chain`typescript
function chain(fn: (val: S) => Result): Result;
`- Returns a new Result by applying
fn to the Success value of this Result
- State handling priority:
1. If this Result is Initial, returns Initial
2. If the next Result (returned by fn) is Initial, returns Initial
3. If this Result is Pending or the next Result is Pending, returns Pending
4. If this Result is Failure, returns Failure with current value
5. If the next Result is Failure, returns Failure with next value
6. Otherwise returns the next ResultExample:
`typescript
const v1 = success(2);
const v2 = failure(new Error());
const v3 = initial;// Result.Success with value "2"
const newVal1 = v1.chain(a => success(a.toString()));
// Result.Failure with value new TypeError()
const newVal2 = v1.chain(a => failure(new TypeError()));
// Result.Failure with value new Error()
const newVal3 = v2.chain(a => success(a.toString()));
// Result.Failure with value new Error()
const newVal4 = v2.chain(a => failure(new TypeError()));
// Result.Initial with no value
const newVal5 = v3.chain(a => failure(new TypeError()));
`The chain method is particularly useful when you need to sequence operations that might fail or be in different states. It handles all possible state combinations according to the priority rules above.
####
mergemergeInOne`typescript
function merge(values: [Result]): Result;
function merge(values: [Result, Result]): Result;
function merge(
values: [Result, Result, Result]
): Result;
// ... until 10 elements
`-
values: Array - Array of Result values which will be merged into Result of Array
- Returns Result which will contain Success if all of array elements was Success, Failureif all of array elements was Failure, Initial if at least one Initial, otherwise Pending.Example:
`typescript
const v1 = initial; // Result.Initial
const v2 = pending; // Result.Pending
const v3 = success(2); // Result.Success
const v4 = success("test"); // Result.Success
const v5 = failure(new Error()); // Result.Failureconst r1 = merge([v1, v2]); // Result.Initial
const r2 = merge([v2, v5]); // Result.Pending
const r3 = merge([v3, v4]); // Result.Success
const r4 = merge([v3, v4, v5]); // Result.Failure
`
#### mergeWithConfig`typescript
function mergeWithConfig(values: Result[], config: { priority: 'failure' | 'pending' }): Result;
`Merges an array of Results with configurable priority between states.
Default behavior (priority: 'pending'):
1. Returns Initial if ANY Result is Initial
2. Returns Pending if ANY Result is Pending (and none are Initial)
3. Returns Failure if ANY Result is Failure (and none are Initial/Pending)
4. Returns Success only if ALL Results are Success
Failure priority (priority: 'failure'):
1. Returns Failure if ANY Result is Failure
2. Returns Initial if ANY Result is Initial
3. Returns Pending if ANY Result is Pending
4. Returns Success only if ALL Results are Success
`typescript
const v1 = success(1);
const v2 = failure('error');
const v3 = pending as Result;// Default behavior - Pending takes precedence
mergeWithConfig([v1, v2, v3], { priority: 'pending' }); // Result.Pending
// Failure priority
mergeWithConfig([v1, v2, v3], { priority: 'failure' }); // Result.Failure('error')
`####
mergeInOne`typescript
function merge(values: [Result]): Result;
function merge(values: [Result, Result]): Result;
function merge(
values: [Result, Result, Result]
): Result;
// ... until 10 elements
`-
values: Array - Array of Result values which will be merged into Result of Array
- Returns Result which will contain Success if all of array elements was Success, Failureif all of array elements was Failure, Initial if at least one Initial, otherwise Pending.Example:
`typescript
const v1 = initial; // Result.Initial
const v2 = pending; // Result.Pending
const v3 = success(2); // Result.Success
const v4 = success("test"); // Result.Success
const v5 = failure(new Error()); // Result.Failureconst r1 = merge([v1, v2]); // Result.Initial
const r2 = merge([v2, v5]); // Result.Pending
const r3 = merge([v3, v4]); // Result.Success
const r4 = merge([v3, v4, v5]); // Result.Failure
`####
mergeInMany`typescript
static mergeInMany(values: [Result]): Result, [S1]>;
static mergeInMany(values: [Result, Result]): Result, [S1, S2]>;
static mergeInMany(
values: [Result, Result, Result]
): Result, [S1, S2, S3]>;
// ... until 10 elements
`-
values: Array - Array of Result values which will be merged into Result of Array
- Returns Result which will contain Success if all of array elements was Success otherwise array of all catched Failure values.Example:
`typescript
const v1 = success(2); // Result.Success
const v2 = failure("test"); // Result.Success
const v3 = failure(new Error()); // Result.Failuremerge([v1, v2]); // Result, [number, string]>.Success
merge([v1, v2, v3]); // Result, [number, string, boolean]>.Failure
`####
initial`typescript
const initial: Result;
`- Returns
Result with Initial state which does not contain value.Example:
`typescript
const v1 = initial; // Result.Initial
`####
pending`typescript
const pending: Result;
`- Returns
Result with Pending state which does not contain value.Example:
`typescript
const v1 = pending; // Result.Initial
`####
failure`typescript
function failure(value: F): Result;
`- Returns
Result with Failure state which contain value with F type.Example:
`typescript
const v1 = failure(new Error()); // Result.Failure
const v2 = failure(new Error()); // Result.Failure
`####
success`typescript
function success(value: S): Result;
`- Returns
Result with Success state which contain value with S type.Example:
`typescript
const v1 = success(2); // Result.Success
const v2 = success(2); // Result.Success
`####
fromsuccess`typescript
function from(value: S): Result;
`- Returns
Result with Success state which contain value with S type.Example:
`typescript
from(2); // Result.Success
`####
fromTryReturns
Success with function result or Failure if function execution throws an error.`typescript
function fromTry(fn: () => R): Result;
``typescript
fromTry(() => 2); // Result.Success
fromTry(() => {
throw new Error("test");
}); // Result.Failure
`
####
fromPromiseReturns promise of
Success if the provided promise fulfilled or Failure with the error value if the provided promise rejected.`typescript
function fromPromise(promise: Promise): Promise>;
``typescript
fromPromise(Promise.resolve(2)); // Promise.Right>
fromPromise(Promise.reject(new Error("test"))); // Promise.Left>
`####
fromMaybe`typescript
function fromMaybe(value: Maybe): Result;
`- Creates
Result from Maybe in Initial or Success state.Example:
`typescript
fromMaybe(just(2)); // Result.Success
fromMaybe(none()); // Result.Initial
`####
fromEither`typescript
function fromEither(value: Either): Result;
`- Creates
Result from Either in Failure or Success state.Example:
`typescript
fromEither(right(10)); // Result.Success
`####
fromNullable`typescript
function fromNullable(value: T): Result>;
`- Creates
Result with Success state which contain value with T type if value is not null or undefined and initial otherwise.Example:
`typescript
fromNullable(10); // Result.Success
fromNullable(null as Nullable); // Result.Initial
`####
isResult`typescript
function isResult(value: unknown | Result): value is Result;
`- Returns
boolean if given value is instance of Result constructor.Example:
`typescript
const value: unknown = 2;
if (isResult(value)) {
// ... value is Result at this block
}
`####
Result#isInitial`typescript
function isInitial(): boolean;
`- Returns
true if state of Result is Initial otherwise falseExample:
`typescript
const v1 = success(2);
const v2 = failure(2);
const v3 = initial();v1.isInitial(); // false
v2.isInitial(); // false
v3.isInitial(); // true
`####
Result#isPending`typescript
function isPending(): boolean;
`- Returns
true if state of Result is Pending otherwise falseExample:
`typescript
const v1 = success(2);
const v2 = failure(2);
const v3 = pending();v1.isPending(); // false
v2.isPending(); // false
v3.isPending(); // true
`####
Result#isFailure`typescript
function isFailure(): boolean;
`- Returns
true if state of Result is Failure otherwise falseExample:
`typescript
const v1 = success(2);
const v2 = failure(2);v1.isFailure(); // false
v2.isFailure(); // true
`####
Result#isSuccess`typescript
function isSuccess(): boolean;
`- Returns
true if state of Result is Success otherwise falseExample:
`typescript
const v1 = success(2);
const v2 = failure(2);v1.isSuccess(); // true
v2.isSuccess(); // false
`
#### Result#equal`typescript
function equal(x: Result, extractor?: (item: S): T): boolean;
`- The
equal method compares the current Result instance with another Result instance for equality. It provides flexibility in how equality is determined through an optional field extractor.Example:
`typescript
// Comparing entire values
const result1 = success(10);
const result2 = success(10);
const result3 = success(20);
result1.equal(result2); // true
result1.equal(result3); // false// Comparing with a field extractor
interface User { id: number; name: string; }
const user1 = success({ id: 1, name: 'Alice' });
const user2 = success({ id: 1, name: 'Bob' });
user1.equal(user2, user => user.id); // true
`
####
Result#or`typescript
function or(x: Result): Result;
`- Returns
Result. If state of this is Success then this will be returned otherwise x argument will be returnedExample:
`typescript
const v1 = success(2);
const v2 = failure("Error 1");
const v3 = failure("Error 2");
const v4 = success(3);
const v5 = initial();v1.or(v2); // v1 will be returned
v2.or(v1); // v1 will be returned
v2.or(v3); // v3 will be returned
v1.or(v4); // v1 will be returned
v5.or(v1); // v1 will be returned
v2.or(v3).or(v1); // v1 will be returned
v2.or(v1).or(v3); // v1 will be returned
v1.or(v2).or(v3); // v1 will be returned
v2.or(v5).or(v3); // v3 will be returned
`####
Result#join`typescript
function join(this: Result>): Result;
`-
this: Result - Result instance which contains other Result instance as Success value.
- Returns unwrapped Result - if current Result has Success state and inner Result has Success state then returns inner Result Success, if inner Result has Failure state then return inner Result Failure otherwise outer Result Failure.Example:
`typescript
const v1 = success(success(2));
const v2 = success(failure(new Error()));
const v3 = failure>(new TypeError());v1.join(); // Result.Success with value 2
v2.join(); // Result.Failure with value new Error
v3.join(); // Result.Failure with value new TypeError
`####
Result#mapResult#mapSuccess`typescript
function map(fn: (val: S) => NewS): Result;
`- Returns mapped by
fn function value wrapped by Result if Result is Success otherwise Result with current valueExample:
`typescript
const v1 = success(2);
const v2 = failure(new Error());const newVal1 = v1.map(a => a.toString()); // Result.Success with value "2"
const newVal2 = v2.map(a => a.toString()); // Result.Failure with value new Error()
`####
Result#mapSuccess`typescript
function mapSuccess(fn: (val: S) => NewS): Result;
`- Returns mapped by
fn function value wrapped by Result if Result is Success otherwise Result with current valueExample:
`typescript
const v1 = success(2);
const v2 = failure(new Error());const newVal1 = v1.mapSuccess(a => a.toString()); // Result.Success with value "2"
const newVal2 = v2.mapSuccess(a => a.toString()); // Result.Failure with value new Error()
`####
Result#mapLeft`typescript
function mapFailure(fn: (val: F) => NewF): Result;
`- Returns mapped by
fn function value wrapped by Result if Result is Failure otherwise Result with current valueExample:
`typescript
const v1 = success(2);
const v2 = failure(new Error());const newVal1 = v1.mapFailure(a => a.toString()); // Result.Right with value 2
const newVal2 = v2.mapFailure(a => a.toString()); // Result.Left with value "Error"
`#####
Result#asyncMap`typescript
function asyncMap(fn: (val: S) => Promise): Promise>;
`- Returns
Promise with mapped by fn function value wrapped by Result if Result is Success otherwise Result with current valueExample:
`typescript
const v1 = success(2);
const v2 = failure(new Error());// Promise.Success> with value "2"
const newVal1 = v1.asyncMap(a => Promise.resolve(a.toString()));
// Promise.Failure> with value new Error()
const newVal2 = v2.asyncMap(a => Promise.resolve(a.toString()));
`#####
Result#apply`typescript
function apply(this: Result B>, arg: Result): Result;
function apply(this: Result, fn: Result B>): Result;
`-
this | fn - function wrapped by Result, which should be applied to value arg
- arg | this - value which should be applied to fn
- Returns mapped by fn function value wrapped by Result if Result is Success otherwise Result with current valueExample:
`typescript
const v1 = success(2);
const v2 = failure(new Error());
const fn1 = success number>((a: number) => a * 2);
const fn2 = failure number>(new Error());const newVal1 = fn1.apply(v1); // Result.Right with value 4
const newVal2 = fn1.apply(v2); // Result.Left with value new Error()
const newVal3 = fn2.apply(v1); // Result.Left with value new Error()
const newVal4 = fn2.apply(v2); // Result.Left with value new Error()
`#####
Result#asyncApplyResult#apply`typescript
asyncApply(
this: Result | S) => Promise>,
arg: Result>): Promise>;
asyncApply(
this: Result>,
fn: Result | S) => B>>): Promise>;
`-
this | fn - function wrapped by Result, which should be applied to value arg
- arg | this - value which should be applied to fn
- Returns Promise with mapped by fn function value wrapped by Result if Result is Success otherwise Result with current valueExample:
`typescript
const v1 = success(2);
const v2 = failure(new Error());
const fn1 = success Promise>((a: number) => Promise.resolve(a * 2));
const fn2 = failure Promise>(new Error());const newVal1 = fn1.asyncApply(v1); // Promise.Right> with value 4
const newVal2 = fn1.asyncApply(v2); // Promise.Left> with value new Error()
const newVal3 = fn2.asyncApply(v1); // Promise.Left> with value new Error()
const newVal4 = fn2.asyncApply(v2); // Promise.Left> with value new Error()
`####
Result#chain`typescript
function chain(fn: (val: S) => Result): Result;
`- Returns a new Result by applying
fn to the Success value of this Result
- State handling priority:
1. If this Result is Initial, returns Initial
2. If the next Result (returned by fn) is Initial, returns Initial
3. If this Result is Pending or the next Result is Pending, returns Pending
4. If this Result is Failure, returns Failure with current value
5. If the next Result is Failure, returns Failure with next value
6. Otherwise returns the next ResultExample:
`typescript
const v1 = success(2);
const v2 = failure(new Error());
const v3 = initial;// Result.Success with value "2"
const newVal1 = v1.chain(a => success(a.toString()));
// Result.Failure with value new TypeError()
const newVal2 = v1.chain(a => failure(new TypeError()));
// Result.Failure with value new Error()
const newVal3 = v2.chain(a => success(a.toString()));
// Result.Failure with value new Error()
const newVal4 = v2.chain(a => failure(new TypeError()));
// Result.Initial with no value
const newVal5 = v3.chain(a => failure(new TypeError()));
`The chain method is particularly useful when you need to sequence operations that might fail or be in different states. It handles all possible state combinations according to the priority rules above.
#####
Result#asyncChain`typescript
function asyncChain(fn: (val: S) => Promise>): Promise>;
`- Returns
Promise with mapped by fn function value wrapped by Result if Result is Success and returned by fn value is Success too otherwise Result in other state, Initial pwns Pending and Failure.Example:
`typescript
const v1 = success(2);
const v2 = failure(new Error());
const v3 = initial;// Promise.Success> with value "2"
const newVal1 = v1.asyncChain(a => Promise.resolve(right(a.toString())));
// Promise.Failure> with value new TypeError()
const newVal2 = v1.asyncChain(a => Promise.resolve(left(new TypeError()));
// Promise.Failure> with value new Error()
const newVal3 = v2.asyncChain(a => Promise.resolve(right(a.toString())));
// Promise.Failure> with value new Error()
const newVal4 = v2.asyncChain(a => Promise.resolve(left(new TypeError())));
// Promise.Initial> with no value
const newVal5 = v3.asyncChain(a => Promise.resolve(failure(new TypeError())));
`####
Result#toEither`typescript
function toEither(onInitial: () => F, onPending: () => F): Either;
`- Converts
Result into Either in Left or Success state with fallbacks for Initial and Pending states.Example:
`typescript
success(10).toEither(
() => "initial state",
() => "pending state"
); // Either.Right
`####
Result#toMaybe`typescript
function toMaybe(): Maybe;
`- Converts
Result into Maybe in Just state if Result is in Success state or to Maybe in None state otherwise.Example:
`typescript
success(10).toMaybe(); // Maybe.Just
`####
Result#toNullable`typescript
function toNullable(): S | null;
`- Returns S if
Result is in Success state and null otherwiseExample:
`typescript
success(10).toNullable(); // number | null
`####
Result#toUndefined`typescript
function toUndefined(): S | undefined;
`- Returns S if
Result is in Success state and undefined otherwiseExample:
`typescript
success(10).toUndefined(); // number | undefined
`####
Result#unwrap`typescript
function unwrap(): S;
`- Returns S if
Result is in Success state and throws otherwise via provided factory or pure ErrorExample:
`typescript
success(10).unwrap(); // number
initial.unwrap(); // throws default (Error)
pending.unwrap({ failure: () => new Error('Custom')}); // throws custom (Error)
`####
Result#unwrapOr`typescript
function unwrapOr(s: S): S;
`- Returns the success value if Result is Success, otherwise returns the provided default value.
Example:
`typescript
const v1 = success(2);
const v2 = failure(new Error());
v1.unwrapOr(3); // returns 2
v2.unwrapOr(3); // returns 3
`
#### Result#unwrapOrElse`typescript
function unwrapOrElse(f: (l: F) => S): S;
`- Returns the success value if Result is Success, otherwise returns the result of calling the provided function with the failure value.
Example:
`typescript
const v1 = success(2);
const v2 = failure(3);
v1.unwrapOrElse(x => x * 2); // returns 2
v2.unwrapOrElse(x => x *2); // returns 6
`####
Result#fold`typescript
function fold(onInitial: () => D, onPending: () => D, onFailure: (failure: F) => D, onSuccess: (success: S) => D): D;
`- Transforms the Result value into type D by providing handlers for all possible states
- Parameters:
-
onInitial: () => D - Handler for Initial state
- onPending: () => D - Handler for Pending state
- onFailure: (failure: F) => D - Handler for Failure state, receives the failure value
- onSuccess: (success: S) => D - Handler for Success state, receives the success value
- Returns the result of calling the appropriate handler based on the Result stateExample:
`typescript
const onInitial = () => "it's initial"
const onPending = () => "it's pending"
const onFailure = (err) => "it's failure"
const onSuccess = (data) => ${data + 1}const v1 = initial;
const v2 = pending;
const v3 = failure('error');
const v4 = success(21);
v1.fold(onInitial, onPending, onFailure, onSuccess) // "it's initial"
v2.fold(onInitial, onPending, onFailure, onSuccess) // "it's pending"
v3.fold(onInitial, onPending, onFailure, onSuccess) // "it's failure"
v4.fold(onInitial, onPending, onFailure, onSuccess) // "22"
`The fold method is particularly useful when you need to handle all possible states of a Result and transform them into a single type. This pattern is common when you need to:
- Display different UI states
- Convert Result states into a common format
- Handle all possible outcomes in a type-safe way
####
Result#filter`typescript
function filter(predicate: (value: S) => boolean): Result;
`Validates a Success value using a predicate. If the predicate returns false, converts the Success to a Failure using the success value.
`typescript
// Age validation
const age = success(15);
const isAdult = age.filter(age => age >= 18);
// Result.Failure with value 15// Chaining validations
const validAge = success(25)
.filter(age => age >= 0) // minimum age
.filter(age => age <= 120); // maximum age
// Result.Success with value 25
`####
Result#filterMap`typescript
function filterMap(f: (value: S) => Result): Result;
`Combines filtering and mapping in one operation. Useful for transformations that might fail.
`typescript
const parseIfPositive = (n: number) =>
n > 0 ? success(n.toString()) : failure(n);success(5).filterMap(parseIfPositive)
// Result.Success with value "5"
success(-1).filterMap(parseIfPositive)
// Result.Failure with value -1
``typescript
failure('error').filter(x => true) // stays Failure
initial.filter(x => true) // stays Initial
pending.filter(x => true) // stays Pendingfailure('error').filterMap(fn) // stays Failure
initial.filterMap(fn) // stays Initial
pending.filterMap(fn) // stays Pending
`####
Result#tap`typescript
function tap(f: (value: S) => void): Result;
`Executes a side effect function if the Result is Success, then returns the original Result unchanged.
Useful for logging, debugging, or other side effects without modifying the Result chain.
`typescript
success(5)
.tap(x => console.log('Value:', x)) // logs "Value: 5"
.map(x => x * 2); // Result.Success(10)failure('error')
.tap(x => console.log('Value:', x)) // nothing logged
.map(x => x * 2); // Result.Failure('error')
`####
Result#tapFailure`typescript
function tapFailure(f: (value: F) => void): Result;
`Executes a side effect function if the Result is Failure, then returns the original Result unchanged.
Useful for error logging or debugging without modifying the Result chain.
`typescript
success(5)
.tapFailure(e => console.error(e)) // nothing logged
.map(x => x * 2); // Result.Success(10)failure(new Error('oops'))
.tapFailure(e => console.error(e)) // logs Error: oops
.map(x => x * 2); // Result.Failure(Error: oops)
`
####
Result#recover`typescript
function recover(value: S): Result;
`Recovers from a Failure state by providing a default success value.
`typescript
const v1 = failure('error');
const v2 = success(5);v1.recover(42); // Result.Success with value 42
v2.recover(42); // Result.Success with value 5 (unchanged)
`####
Result#recoverWith`typescript
function recoverWith(f: (error: F) => Result): Result;
`Recovers from a Failure state by applying a function that returns a new Result.
Useful for handling specific error cases differently or transforming errors.
`typescript
const handler = (error: string): Result =>
error === 'known' ? success(42) : failure(new Error('still failed'));failure('known').recoverWith(handler); // Result.Success(42)
failure('unknown').recoverWith(handler); // Result.Failure(Error: still failed)
success(5).recoverWith(handler); // Result.Success(5)
// Initial and Pending states pass through
initial.recoverWith(handler); // Result.Initial
pending.recoverWith(handler); // Result.Pending
`
####
Result#zip`typescript
function zip(other: Result): Result;
`Combines two Results into a Result containing a tuple of their success values.
Returns Failure if either Result is a Failure.
`typescript
const num = success(2);
const str = success('test');num.zip(str) // Result.Success([2, 'test'])
num.zip(failure('error')) // Result.Failure('error')
`####
Result#zipWith`typescript
function zipWith(
other: Result,
f: (a: S, b: S2) => R
): Result;
`Combines two Results using a function. Returns Failure if either Result is a Failure.
`typescript
const num1 = success(2);
const num2 = success(3);num1.zipWith(num2, (a, b) => a + b) // Result.Success(5)
num1.zipWith(failure('error'), (a, b) => a + b) // Result.Failure('error')
`####
Result#bimap`typescript
function bimap(
failureMap: (f: F) => NF,
successMap: (s: S) => NS
): Result;
`Maps both the Failure and Success values of a Result simultaneously. Useful for transforming both possible outcomes in one operation.
`typescript
const result = success(42);// Transform both success and failure values
const transformed = result.bimap(
(error: string) => new Error(error), // transform failure
(value: number) => value.toString() // transform success
);
// Result.Success('42')
const failed = failure('oops');
const transformedFailure = failed.bimap(
(error: string) => new Error(error),
(value: number) => value.toString()
);
// Result.Failure(Error: oops)
// Initial and Pending states pass through unchanged
initial.bimap(f, s) // Result.Initial
pending.bimap(f, s) // Result.Pending
`#### Helpers
`typescript
// Value from Result instance
const { value } = success(2); // number | Error | undefined
const { value } = success(2); // number | undefined
const { value } = failure(new Error()); // number | Error | undefined
const { value } = failure(new Error()); // Error | undefined
``MIT (c)