# jseither

> A simple, useful, but somewhat incorrect implementation of the Either monad in Javascript.

Latest version **0.3.0** (published 2017-03-27) · MIT license · 0 weekly downloads

## Install

```sh
npm install jseither
pnpm add jseither
yarn add jseither
bun add jseither
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.3.0 |
| Published | 2017-03-27 |
| First published | 2017-03-27 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Erich Dalton |
| Maintainers | takakoshimizu |

## Links

- npm: https://www.npmjs.com/package/jseither
- Repository: https://github.com/takakoshimizu/either-js
- Homepage: https://github.com/takakoshimizu/either-js#readme
- Issues: https://github.com/takakoshimizu/either-js/issues
- npm.io page: https://npm.io/package/jseither

## Recent versions

- 0.3.0 (latest) — 2017-03-27

## README

# Maybe-JS

A simple, useful, and slightly incorrect implementation of the Either monad in Javascript.

## Features

* Process data in chains.
* Preserve any error that occurs during processing.
* Act based on whether processing chain completed successfully or not.
* Avoid runtime errors.

### Why incorrect?

For starters, some implementation is about what's useful in JS rather than following laws. For example, `id(Either.Right.of(1)) !== Either.Right(1).map(id)`. The value will remain the same, but the referential equality is lost.

But hey, the usefulness is real.

### Difference from Maybe?

Maybe can be used when you just want to know if something exists or not, but do not
care about why anything went wrong. Either is roughly the same general idea, except
that it captures and preserves the error that caused the chain to be broken, so that
you can report on it at the end.

## Usage

More detail to come.

```JS
import Either from 'jseither';
const a = Either.of('test');

const b = a.map(test => `${test} post, please ignore`);
// => Right { 'test post, please ignore' }

const c = b.map(v => v.unsupportedOp());
// => Left { ' TypeError: v.unsupportedOp is not a function' }

b.value();
// => 'test post, please ignore'

c.value();
// => TypeError

b instanceof Right;
// => true

c instanceof Left;
// => true

c.withRight(val => console.log(val)).withleft(err => console.error(err));
// => TypeError is logged
```

---
_Source: https://npm.io/package/jseither · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
