monapt
TypeScript icon, indicating that this package has built-in type declarations

2.1.0 • Public • Published

Monapt

npm version Build Status Coverage Status

semantic-release Commitizen friendly Conventional Commits

Monapt helps you better manage null, undefined, exceptions, and other mildly interesting phenomena. It handles them through the Option, Try, and Future abstractions.

Setup

$ npm install monapt

APIs

Usage

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.

Changes in 1.0

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.

Migrating from 0.7.1

Breaking Changes

  • 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 to Option::flatten.
  • Monapt::future has been renamed to Future::create. It now accepts a when.Promise<A> | when.Thenable<A> | A.
  • Option#reject has been renamed to Option#filterNot.
  • Try#reject has been removed.

These are all backed by type definitions, so compiling your code via TypeScript should reveal any breakages.

Credits

This repo couldn't have been possible without yaakaito/monapt. In his absence, I'll continue improving upon his hard work.

Package Sidebar

Install

npm i monapt

Weekly Downloads

1,474

Version

2.1.0

License

MIT

Unpacked Size

34.2 kB

Total Files

12

Last publish

Collaborators

  • jiaweihli