@nutgaard/maybe-ts

Maybe monad for typescript inspired by elm's Maybe

Usage no npm install needed!

<script type="module">
  import nutgaardMaybeTs from 'https://cdn.skypack.dev/@nutgaard/maybe-ts';
</script>

README

Maybe-ts

styled with prettier Travis codecov dependencies Status

Maybe monad for typescript inspired by elm's Maybe.

Installation:

npm install @nutgaard/maybe-ts --save

Examples

The library exports two different ways of using the Maybe-monad, functional and classical.

NB! Uses different ways of importing the library.

Function:

import Maybe from 'maybe-ts';

Maybe.map((value) => value.toUpperCase(), Maybe.just('Hello, World'));

// If you use a library for `compose`/`flow`/`pipe` or similar concepts. (See ./test/pipe.ts example)
pipe(
  Maybe.just('Hello, World'),
  Maybe.map((value: string) => value.toUpperCase())
);

// Or, with the use of the pipe-operator
Maybe.just('Hello, World')
  |> Maybe.map((value) => value.toUpperCase())

Classical:

import { MaybeCls as Maybe } from '../src/maybe-ts';

Maybe.just('Hello, World')
  .map((value) => value.toUpperCase())

Types

Full documentation of types can be seen here

Credits

Made using the awesome typescript library starter