Module: data.either

Stability:3 - Stable
Bug Tracker:https://github.com/folktale/data.either/issues
Version:1.2.0
Repository:https://github.com/folktale/data.either
Portability:Portable
npm package:data.either

A structure for disjunctions (e.g.: computations that may fail).

The Either(α, β) structure represents the logical disjunction between α and β. In other words, Either may contain either a value of type α, or a value of type β, at any given time, and it’s possible to know which kind of value is contained in it.

This particular implementation is biased towards right values (β), thus common projections (e.g.: for the monadic instance) will take the right value over the left one.

Loading

Require the data.either package, after installing it:

var Either = require('data.either')

This gives you back an data.either.Either object.

Why?

A common use of this structure is to represent computations that may fail when you want to provide additional information on the failure. This can force failures and their handling to be explicit, avoiding the problems associated with throwing exceptions: non locality, abnormal exits, unintended stack unwinding, etc.

Additional resources

Types and structures

Either

class data.either.Either
type Either(α, β) = Left(α) | Right(β)

implements
  Applicative(β), Functor(β), Chain(β), Monad(β), ToString

Represents the logical disjunction between α and β.