@nutgaard/maybe-ts
v1.4.0
Published
Maybe monad for typescript inspired by elm's Maybe
Downloads
8
Maintainers
Readme
Maybe-ts
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