2.3.0 • Published 8 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: Tand creates aSuccess<T>. Its predicateisSuccess(x)returns true ifxis aSuccess<T>. - The
failure(error)function takes someerror: Errorand creates aFailure. Its predicateisFailure(x)returns true ifxis aFailure. - The
pendingconstant does not take anything. Its predicateisPending(x)returns true ifxis 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.