/** * This file contains the Either algebraic data type. Either is used to * represent two exclusive types. Generally, Either is used to represent either * a successful computation or a failed computation, with the result of the * failed computation being kept in Left. * * @module Either * @since 2.0.0 */ import "./_dnt.polyfills.js"; import type { $, Kind, Out } from "./kind.js"; import type { Applicable } from "./applicable.js"; import type { Bimappable } from "./bimappable.js"; import type { Combinable } from "./combinable.js"; import type { Comparable } from "./comparable.js"; import type { Failable } from "./failable.js"; import type { Filterable } from "./filterable.js"; import type { Flatmappable } from "./flatmappable.js"; import type { Foldable } from "./foldable.js"; import type { Initializable } from "./initializable.js"; import type { Mappable } from "./mappable.js"; import type { Predicate } from "./predicate.js"; import type { Refinement } from "./refinement.js"; import type { Showable } from "./showable.js"; import type { Sortable } from "./sortable.js"; import type { Traversable } from "./traversable.js"; import type { Wrappable } from "./wrappable.js"; import * as O from "./option.js"; /** * @since 2.0.0 */ export type Left = { tag: "Left"; left: L; }; /** * @since 2.0.0 */ export type Right = { tag: "Right"; right: R; }; /** * @since 2.0.0 */ export type Either = Left | Right; /** * @since 2.0.0 */ export interface KindEither extends Kind { readonly kind: Either, Out>; } /** * @since 2.0.0 */ export interface KindRightEither extends Kind { readonly kind: Either>; } /** * @since 2.0.0 */ export declare function left(left: E): Either; /** * @since 2.0.0 */ export declare function right(right: A): Either; /** * @since 2.0.0 */ export declare function wrap(a: A): Either; /** * @since 2.0.0 */ export declare function fail(b: B): Either; /** * @since 2.0.0 */ export declare function fromNullable(fe: () => E): (a: A) => Either>; /** * @since 2.0.0 */ export declare function tryCatch(fn: (...as: AS) => A, onError: (e: unknown) => E): (...as: AS) => Either; /** * @since 2.0.0 */ export declare function fromPredicate(refinement: Refinement): (a: A) => Either; export declare function fromPredicate(predicate: Predicate): (a: A) => Either; /** * @since 2.0.0 */ export declare function match(onLeft: (left: L) => B, onRight: (right: R) => B): (ta: Either) => B; /** * @since 2.0.0 */ export declare function getOrElse(onLeft: (e: E) => A): (ma: Either) => A; /** * @since 2.0.0 */ export declare function getRight(ma: Either): O.Option; /** * @since 2.0.0 */ export declare function getLeft(ma: Either): O.Option; /** * @since 2.0.0 */ export declare function isLeft(m: Either): m is Left; /** * @since 2.0.0 */ export declare function isRight(m: Either): m is Right; /** * @since 2.0.0 */ export declare function bimap(fbj: (b: B) => J, fai: (a: A) => I): (ta: Either) => Either; /** * @since 2.0.0 */ export declare function swap(ma: Either): Either; /** * @since 2.0.0 */ export declare function map(fai: (a: A) => I): (ta: Either) => Either; /** * @since 2.0.0 */ export declare function mapSecond(fbj: (b: B) => J): (ta: Either) => Either; /** * @since 2.0.0 */ export declare function apply(ua: Either): (ufai: Either I>) => Either; /** * @since 2.0.0 */ export declare function flatmap(fati: (a: A) => Either): (ta: Either) => Either; /** * @since 2.0.0 */ export declare function flatmapFirst(faui: (a: A) => Either): (ta: Either) => Either; /** * @since 2.0.0 */ export declare function recover(fbui: (b: B) => Either): (ua: Either) => Either; /** * @since 2.0.0 */ export declare function alt(tb: Either): (ta: Either) => Either; /** * @since 2.0.0 */ export declare function fold(foao: (o: O, a: A) => O, o: O): (ta: Either) => O; /** * @since 2.0.0 */ export declare function traverse(A: Applicable & Mappable & Wrappable): (faui: (a: A) => $) => (ta: Either) => $, J, K], [L], [M]>; /** * @since 2.0.0 */ export declare function getShowableEither(SB: Showable, SA: Showable): Showable>; /** * @since 2.0.0 */ export declare function getComparableEither(SB: Comparable, SA: Comparable): Comparable>; /** * @since 2.0.0 */ export declare function getSortableEither(OB: Sortable, OA: Sortable): Sortable>; /** * @since 2.0.0 */ export declare function getCombinableEither(CA: Combinable, CB: Combinable): Combinable>; /** * @since 2.0.0 */ export declare function getInitializableEither(CA: Initializable, CB: Initializable): Initializable>; /** * @since 2.0.0 */ export declare function getFlatmappableRight({ combine }: Combinable): Flatmappable>; /** * @since 2.0.0 */ export declare function getFilterableEither(I: Initializable): Filterable>; /** * @since 2.0.0 */ export declare const ApplicableEither: Applicable; /** * @since 2.0.0 */ export declare const BimappableEither: Bimappable; /** * @since 2.0.0 */ export declare const FailableEither: Failable; /** * @since 2.0.0 */ export declare const FlatmappableEither: Flatmappable; /** * @since 2.0.0 */ export declare const MappableEither: Mappable; /** * @since 2.0.0 */ export declare const FoldableEither: Foldable; /** * @since 2.0.0 */ export declare const TraversableEither: Traversable; /** * @since 2.0.0 */ export declare const WrappableEither: Wrappable; /** * @since 2.0.0 */ export declare const tap: (fn: (value: A) => void) => (ua: Either) => Either; /** * @since 2.0.0 */ export declare const bind: (name: Exclude, faui: (a: A) => Either) => (ua: Either) => Either; /** * @since 2.0.0 */ export declare const bindTo: (name: N) => (ua: Either) => Either;