/** * Either represents a value that may be one of two types. * * An Either is either a Left or Right. Mapping and related functions over the * Left side returns the value unchanged. When the value is Right * functions are applied as normal. * * The Either concept is often used to accomodate error handling but there * are other places it may come in handy. * * An important point to note when using this type is that the left side * remains the same while chaining. That means, the types Either * and Either are two different types that can not be sequenced * together via map,chain etc. * * This turns up compiler errors in unexpected places and is sometimes rectified * by extracting the values out of the Either type completley and constructing * a fresh one. */ /** imports */ import { Functor } from './functor'; import { Apply } from '../control/apply'; import { Alt } from '../control/alt'; import { Chain } from '../control/chain'; import { Monad } from '../control/monad'; import { Extend } from '../control/extend'; import { Eq } from './eq'; import { Maybe } from './maybe'; /** * The abstract Either class. * * This is the type that will be used in signatures. */ export declare abstract class Either implements Functor, Apply, Alt, Chain, Monad, Extend, Eq> { /** * left constructor helper. */ static left: (a: A) => Either; /** * right constructor helper. */ static right: (b: B) => Either; of(value: R): Either; abstract map(_: (r: R) => B): Either; abstract lmap(f: (l: L) => B): Either; abstract bimap(f: (l: L) => A, g: (r: R) => B): Either; abstract alt(a: Either): Either; abstract chain(f: (r: R) => Either): Either; abstract ap(e: Either B>): Either; abstract extend(f: (_: Either) => B): Either; abstract fold(f: (l: L) => B, g: (r: R) => B): B; abstract eq(m: Either): boolean; /** * orElse allows an alternative to be produced from a function * when the Either is Left. */ abstract orElse(_: (l: L) => Either): Either; /** * orRight allows an alternative value to be produced from * a function when the Either is Right. */ abstract orRight(_: (l: L) => R): Either; /** * isLeft test. */ abstract isLeft(): boolean; /** * isRight test. */ abstract isRight(): boolean; /** * takeLeft extracts the value from the Left side. */ abstract takeLeft(): L; /** * takeRight extracts the value from the Right side. * * Will throw an error if the value is not Right. */ abstract takeRight(): R; /** * right is an alias for takeRight. */ abstract right(): R; /** * left is an alias for takeLeft. */ abstract left(): L; /** * toMaybe transformation. */ abstract toMaybe(): Maybe; } /** * Left side of the Either implementation. */ export declare class Left extends Either { value: L; constructor(value: L); map(_: (r: R) => B): Either; lmap(f: (l: L) => B): Either; bimap(f: (l: L) => A, _: (r: R) => B): Either; alt(a: Either): Either; chain(_: (r: R) => Either): Either; ap(_: Either B>): Either; extend(_: (_: Either) => B): Either; fold(f: (l: L) => B, _: (r: R) => B): B; eq(m: Either): boolean; orElse(f: (l: L) => Either): Either; orRight(f: (l: L) => R): Either; isLeft(): boolean; isRight(): boolean; takeLeft(): L; left(): L; takeRight(): R; right(): R; toMaybe(): Maybe; } /** * Right side implementation. */ export declare class Right extends Either { value: R; constructor(value: R); map(f: (r: R) => B): Either; lmap(_: (l: L) => B): Either; bimap(_: (l: L) => A, g: (r: R) => B): Either; alt(_: Either): Either; chain(f: (r: R) => Either): Either; ap(e: Either B>): Either; extend(f: (ex: Either) => B): Either; eq(m: Either): boolean; fold(_: (l: L) => B, g: (r: R) => B): B; orElse(_: (l: L) => Either): Either; orRight(_: (l: L) => R): Either; isLeft(): boolean; isRight(): boolean; takeLeft(): L; left(): L; takeRight(): R; right(): R; toMaybe(): Maybe; } /** * left constructor helper. */ export declare const left: (a: A) => Either; /** * right constructor helper. */ export declare const right: (b: B) => Either; /** * fromBoolean constructs an Either using a boolean value. */ export declare const fromBoolean: (b: boolean) => Either; /** * either given two functions, first for Left, second for Right, will return * the result of applying the appropriate function to an Either's internal value. */ export declare const either: (f: (a: A) => C) => (g: (b: B) => C) => (e: Either) => C;