Maybe monad for typescript inspired by elm's Maybe.
npm install @nutgaard/maybe-ts --save
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())
Full documentation of types can be seen here
Made using the awesome typescript library starter