moneo-ts
v1.6.0
Published
monad library for typescript
Downloads
9
Maintainers
Readme
moneo-ts
A small, simple, but powerful library for functional programming written in TypeScript. It was designed to be extremely lightweight, easy to learn and use.
This library includes a set of powerful tools to write predictable, immutable, and safe code that is easy to reason about. This is especially useful when dealing with complex data structures, async code, or error handling.
Contents
Installation
To use moneo-ts
, install the package via npm.
npm install moneo-ts
# or install a specific version
npm install [email protected]
Examples
Option
import { Option, Some, None } from 'moneo-ts';
Option(0); // Some<number>
Option(''); // Some<string>
Option({}); // Some<{}>
Option(null); // None
Option(undefined); // None
Either
import { Either, Right, Left } from 'moneo-ts';
Right(0); // Right<number>
Right(''); // Right<string>
Right({}); // Right<{}>
Right(null); // Right<null>
Right(undefined); // Right<undefined>
Left(0); // Left<number>
Left(''); // Left<string>
Left({}); // Left<{}>
Left(null); // Left<null>
Left(undefined); // Left<undefined>
IO
import { IO, IOAsync } from 'moneo-ts';
IO(() => 1); // IO<void, number>
IO((env: { a: 1 }) => env.a + 1); // IO<{ a: number }, number>
IOAsync(async () => 1); // IOAsync<void, number>
IOAsync(async (env: { a: 1 }) => env.a + 1); // IOAsync<{ a: number }, number>