eithery
v0.3.0
Published
## Install
Downloads
3
Readme
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.
Clone the repository
Install dependencies
npm install
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