2.3.0 • Published 7 years ago
failable v2.3.0
failable
The failable
library provides three states that together model operations that
can fail. Each state comes with a creator function and a predicate function:
- The
success(data)
function takes somedata: T
and creates aSuccess<T>
. Its predicateisSuccess(x)
returns true ifx
is aSuccess<T>
. - The
failure(error)
function takes someerror: Error
and creates aFailure
. Its predicateisFailure(x)
returns true ifx
is aFailure
. - The
pending
constant does not take anything. Its predicateisPending(x)
returns true ifx
is aPending
.
Different sets of these states model different kinds of failable operations, hence
the name failable
.
- For asynchronous operations, the possible states are
Pending
,Success<T>
, andFailure
. This is called aFailable<T>
and is conceptually close to a promise. - For synchronous operations, the possible states are
Success<T>
andFailure
. This is called aResult<T>
and its closest analog is the result of a function that can throw.
Installation
This package is published on npm as failable
. Simply run npm install --save failable
.
API
See API.md
for
detailed documentation.