Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

jseither

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jseither

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

  • 0.3.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

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.

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

FAQs

Package last updated on 27 Mar 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc