/** * @since 1.0.0 */ import type { Either, Left, Right } from "@fp-ts/core/Either" import { dual } from "@fp-ts/core/Function" import { proto } from "@fp-ts/core/internal/effect" import * as option from "@fp-ts/core/internal/Option" import type { Option } from "@fp-ts/core/Option" /** @internal */ export const isLeft = (ma: Either): ma is Left => ma._tag === "Left" /** @internal */ export const isRight = (ma: Either): ma is Right => ma._tag === "Right" /** @internal */ export const left = (e: E): Either => Object.setPrototypeOf({ _tag: "Left", left: e }, proto) /** @internal */ export const right = (a: A): Either => Object.setPrototypeOf({ _tag: "Right", right: a }, proto) /** @internal */ export const getLeft = ( self: Either ): Option => (isRight(self) ? option.none : option.some(self.left)) /** @internal */ export const getRight = ( self: Either ): Option => (isLeft(self) ? option.none : option.some(self.right)) /** @internal */ export const fromOption = dual( 2, (self: Option, onNone: () => E): Either => option.isNone(self) ? left(onNone()) : right(self.value) )