Monapt helps you better manage null
, undefined
, exceptions, and other mildly interesting
phenomena. It handles them through the
Option
,
Try
,
and Future
abstractions.
$ npm install monapt
import { Option } from 'monapt';
Option(1)
.map((x) => x * 2)
.getOrElse(() => 4);
Docs are undergoing a redesign, and will be published on a separate site.
In the meantime, the sources for the Option
,
Future
, and
Try
classes are readable.
You can also take a look at the tests to get a feel for how to use them.
1.0 was a complete rewrite of Monapt - including everything from the implementation to the tooling to the tests. The result is almost the same API, but more true to the original Scala interface.
- All default exports have been removed to avoid ambiguity.
Future
now depends on native ES6 Promises, and uses them internally when representing promises. Make sure to include a shim if you plan on using Futures.Future#onFailure
has been removed.Future#onSuccess
has been removed.Future#reject
has been removed.Monapt::flatten
has been renamed toOption::flatten
.Monapt::future
has been renamed toFuture::create
. It now accepts awhen.Promise<A> | when.Thenable<A> | A
.Option#reject
has been renamed toOption#filterNot
.Try#reject
has been removed.
These are all backed by type definitions, so compiling your code via TypeScript should reveal any breakages.
This repo couldn't have been possible without yaakaito/monapt. In his absence, I'll continue improving upon his hard work.