import { Left, LEFT } from './Left' import { Right, RIGHT } from './Right' /** * Either data structure. Extremely useful for handling errors or different * logic paths without the use of if-statements. * @name Either * @type */ export type Either = Left | Right export namespace Either { /** * Creates an Either that is of type Right * @name Either.of(value: A): Either */ export const of: (value: B) => Either = Right.of /** * Creates an Either that is of type Left * @name Either.left(value: A): Either */ export const left = Left.of as (value: A) => Either } /** * Returns true if an Either is type Left * @name isLeft(either: Either): Either is Left */ export function isLeft(either: Either): either is Left { return either.hasOwnProperty(LEFT) } /** * Returns true if an Either is type Right * @name isRight(either: Either): either is Right */ export function isRight(either: Either): either is Right { return either.hasOwnProperty(RIGHT) }