eithery
TypeScript icon, indicating that this package has built-in type declarations

0.3.0 • Public • Published

eithery

Install

npm install eithery --save

Usage

Fully typed Either type with fluent syntax and async support.

No usage available yet, but here a small example of what this library looks like:

const isForbidden = async (x: number) => {
  const isForbidden = await isForbiddenNumber(x);
  return isForbidden ? left('ForbiddenNumber' as const) : right(x);
};

const divideByN = (x: number) => (x === 0 ? left('DivideByZero' as const) : right(1 / x));

// Autocompletes as {Either<"DivideByZero", number>}
const result = right(42)
  .chain(divideByN)
  .map(x => x * 2)
  .tap(x => console.log('Current value: ', x));

// Autocompletes as {EitherAsync<"ForbiddenNumber" | "DivideByZero", number>}
const resultAsync = right(42)
  .chainAsync(isForbidden)
  .chain(divideByN)
  .map(x => x * 2)
  .mapAsync(async x => x * 2)
  .tap(x => console.log('Current value: ', x));

// You can await EitherAsync to get a simple Either
const awaitedResult = await resultAsync;

Contributors

If you are interested and want to help out, don't hesitate to contact me or to create a pull request with your fixes / features.

  1. Clone the repository

  2. Install dependencies npm install

  3. Launch unit tests situated in ./tests. The unit tests are written in Jest. npm run test:unit

License

This project is licensed under the MIT License - see the LICENSE.md file for details

Readme

Keywords

Package Sidebar

Install

npm i eithery

Weekly Downloads

1

Version

0.3.0

License

MIT

Unpacked Size

47.6 kB

Total Files

11

Last publish

Collaborators

  • sascha245