https://github.com/patrickap/moneo-ts
Monad library for TypeScript. 🚀
https://github.com/patrickap/moneo-ts
adt async either fp functional io monad option pure typescript
Last synced: 8 months ago
JSON representation
Monad library for TypeScript. 🚀
- Host: GitHub
- URL: https://github.com/patrickap/moneo-ts
- Owner: patrickap
- License: mit
- Created: 2021-07-02T21:33:50.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2023-05-30T10:36:56.000Z (over 2 years ago)
- Last Synced: 2025-02-09T01:09:09.672Z (8 months ago)
- Topics: adt, async, either, fp, functional, io, monad, option, pure, typescript
- Language: TypeScript
- Homepage:
- Size: 475 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.txt
Awesome Lists containing this project
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
- [Option](src/option) monad
- [Either](src/either) monad
- [IO](src/io) / [Async IO](src/io) monad## Installation
To use `moneo-ts`, install the package via npm.
```shell
npm install moneo-ts# or install a specific version
npm install moneo-ts@x.x.x
```## Examples
**Option**
```typescript
import { Option, Some, None } from 'moneo-ts';Option(0); // Some
Option(''); // Some
Option({}); // Some<{}>
Option(null); // None
Option(undefined); // None
```**Either**
```typescript
import { Either, Right, Left } from 'moneo-ts';Right(0); // Right
Right(''); // Right
Right({}); // Right<{}>
Right(null); // Right
Right(undefined); // RightLeft(0); // Left
Left(''); // Left
Left({}); // Left<{}>
Left(null); // Left
Left(undefined); // Left
```**IO**
```typescript
import { IO, IOAsync } from 'moneo-ts';IO(() => 1); // IO
IO((env: { a: 1 }) => env.a + 1); // IO<{ a: number }, number>
IOAsync(async () => 1); // IOAsync
IOAsync(async (env: { a: 1 }) => env.a + 1); // IOAsync<{ a: number }, number>
```