/** * ```ts * type Either = Left | Right * ``` * * Represents a value of one of two possible types (a disjoint union). * * An instance of `Either` is either an instance of `Left` or `Right`. * * A common use of `Either` is as an alternative to `Option` for dealing with possible missing values. In this usage, * `None` is replaced with a `Left` which can contain useful information. `Right` takes the place of `Some`. Convention * dictates that `Left` is used for failure and `Right` is used for success. * * * @example * import * as E from 'fp-ts/Either' * import { pipe } from 'fp-ts/function' * * const double = (n: number): number => n * 2 * * export const imperative = (as: ReadonlyArray): string => { * const head = (as: ReadonlyArray): number => { * if (as.length === 0) { * throw new Error('empty array') * } * return as[0] * } * const inverse = (n: number): number => { * if (n === 0) { * throw new Error('cannot divide by zero') * } * return 1 / n * } * try { * return `Result is ${inverse(double(head(as)))}` * } catch (err: any) { * return `Error is ${err.message}` * } * } * * export const functional = (as: ReadonlyArray): string => { * const head = (as: ReadonlyArray): E.Either => * as.length === 0 ? E.left('empty array') : E.right(as[0]) * const inverse = (n: number): E.Either => * n === 0 ? E.left('cannot divide by zero') : E.right(1 / n) * return pipe( * as, * head, * E.map(double), * E.chain(inverse), * E.match( * (err) => `Error is ${err}`, // onLeft handler * (head) => `Result is ${head}` // onRight handler * ) * ) * } * * assert.deepStrictEqual(imperative([1, 2, 3]), functional([1, 2, 3])) * assert.deepStrictEqual(imperative([]), functional([])) * assert.deepStrictEqual(imperative([0]), functional([0])) * * @since 2.0.0 */ import { Alt2, Alt2C } from './Alt' import { Applicative2, Applicative2C } from './Applicative' import { Apply2 } from './Apply' import { Bifunctor2 } from './Bifunctor' import { Chain2 } from './Chain' import { ChainRec2, ChainRec2C } from './ChainRec' import { Compactable2C } from './Compactable' import { Eq } from './Eq' import { Extend2 } from './Extend' import { Filterable2C } from './Filterable' import { Foldable2 } from './Foldable' import { FromEither2 } from './FromEither' import { Lazy } from './function' import { Functor2 } from './Functor' import { Monad2, Monad2C } from './Monad' import { MonadThrow2, MonadThrow2C } from './MonadThrow' import { Monoid } from './Monoid' import { Option } from './Option' import { Pointed2 } from './Pointed' import { Predicate } from './Predicate' import { ReadonlyNonEmptyArray } from './ReadonlyNonEmptyArray' import { Refinement } from './Refinement' import { Semigroup } from './Semigroup' import { Show } from './Show' import { PipeableTraverse2, Traversable2 } from './Traversable' import { Witherable2C } from './Witherable' /** * @category model * @since 2.0.0 */ export interface Left { readonly _tag: 'Left' readonly left: E } /** * @category model * @since 2.0.0 */ export interface Right { readonly _tag: 'Right' readonly right: A } /** * @category model * @since 2.0.0 */ export declare type Either = Left | Right /** * Constructs a new `Either` holding a `Left` value. This usually represents a failure, due to the right-bias of this * structure. * * @category constructors * @since 2.0.0 */ export declare const left: (e: E) => Either /** * Constructs a new `Either` holding a `Right` value. This usually represents a successful value due to the right bias * of this structure. * * @category constructors * @since 2.0.0 */ export declare const right: (a: A) => Either /** * @category type lambdas * @since 2.0.0 */ export declare const URI = 'Either' /** * @category type lambdas * @since 2.0.0 */ export declare type URI = typeof URI declare module './HKT' { interface URItoKind2 { readonly [URI]: Either } } /** * @category instances * @since 2.0.0 */ export declare const getShow: (SE: Show, SA: Show) => Show> /** * @category instances * @since 2.0.0 */ export declare const getEq: (EL: Eq, EA: Eq) => Eq> /** * Semigroup returning the left-most non-`Left` value. If both operands are `Right`s then the inner values are * concatenated using the provided `Semigroup` * * @example * import { getSemigroup, left, right } from 'fp-ts/Either' * import { SemigroupSum } from 'fp-ts/number' * * const S = getSemigroup(SemigroupSum) * assert.deepStrictEqual(S.concat(left('a'), left('b')), left('a')) * assert.deepStrictEqual(S.concat(left('a'), right(2)), right(2)) * assert.deepStrictEqual(S.concat(right(1), left('b')), right(1)) * assert.deepStrictEqual(S.concat(right(1), right(2)), right(3)) * * @category instances * @since 2.0.0 */ export declare const getSemigroup: (S: Semigroup) => Semigroup> /** * Builds a `Compactable` instance for `Either` given `Monoid` for the left side. * * @category filtering * @since 2.10.0 */ export declare const getCompactable: (M: Monoid) => Compactable2C<'Either', E> /** * Builds a `Filterable` instance for `Either` given `Monoid` for the left side * * @category filtering * @since 2.10.0 */ export declare const getFilterable: (M: Monoid) => Filterable2C<'Either', E> /** * Builds `Witherable` instance for `Either` given `Monoid` for the left side * * @category filtering * @since 2.0.0 */ export declare const getWitherable: (M: Monoid) => Witherable2C<'Either', E> /** * The default [`Applicative`](#applicative) instance returns the first error, if you want to * get all errors you need to provide a way to concatenate them via a `Semigroup`. * * @example * import * as A from 'fp-ts/Apply' * import * as E from 'fp-ts/Either' * import { pipe } from 'fp-ts/function' * import * as S from 'fp-ts/Semigroup' * import * as string from 'fp-ts/string' * * const parseString = (u: unknown): E.Either => * typeof u === 'string' ? E.right(u) : E.left('not a string') * * const parseNumber = (u: unknown): E.Either => * typeof u === 'number' ? E.right(u) : E.left('not a number') * * interface Person { * readonly name: string * readonly age: number * } * * const parsePerson = ( * input: Record * ): E.Either => * pipe( * E.Do, * E.apS('name', parseString(input.name)), * E.apS('age', parseNumber(input.age)) * ) * * assert.deepStrictEqual(parsePerson({}), E.left('not a string')) // <= first error * * const Applicative = E.getApplicativeValidation( * pipe(string.Semigroup, S.intercalate(', ')) * ) * * const apS = A.apS(Applicative) * * const parsePersonAll = ( * input: Record * ): E.Either => * pipe( * E.Do, * apS('name', parseString(input.name)), * apS('age', parseNumber(input.age)) * ) * * assert.deepStrictEqual(parsePersonAll({}), E.left('not a string, not a number')) // <= all errors * * @category error handling * @since 2.7.0 */ export declare const getApplicativeValidation: (SE: Semigroup) => Applicative2C<'Either', E> /** * The default [`Alt`](#alt) instance returns the last error, if you want to * get all errors you need to provide a way to concatenate them via a `Semigroup`. * * @example * import * as E from 'fp-ts/Either' * import { pipe } from 'fp-ts/function' * import * as S from 'fp-ts/Semigroup' * import * as string from 'fp-ts/string' * * const parseString = (u: unknown): E.Either => * typeof u === 'string' ? E.right(u) : E.left('not a string') * * const parseNumber = (u: unknown): E.Either => * typeof u === 'number' ? E.right(u) : E.left('not a number') * * const parse = (u: unknown): E.Either => * pipe( * parseString(u), * E.alt(() => parseNumber(u)) * ) * * assert.deepStrictEqual(parse(true), E.left('not a number')) // <= last error * * const Alt = E.getAltValidation(pipe(string.Semigroup, S.intercalate(', '))) * * const parseAll = (u: unknown): E.Either => * Alt.alt(parseString(u), () => parseNumber(u)) * * assert.deepStrictEqual(parseAll(true), E.left('not a string, not a number')) // <= all errors * * @category error handling * @since 2.7.0 */ export declare const getAltValidation: (SE: Semigroup) => Alt2C<'Either', E> /** * @category mapping * @since 2.0.0 */ export declare const map: (f: (a: A) => B) => (fa: Either) => Either /** * @category instances * @since 2.7.0 */ export declare const Functor: Functor2 /** * @category constructors * @since 2.7.0 */ export declare const of: (a: A) => Either /** * @category instances * @since 2.10.0 */ export declare const Pointed: Pointed2 /** * Less strict version of [`ap`](#ap). * * The `W` suffix (short for **W**idening) means that the error types will be merged. * * @since 2.8.0 */ export declare const apW: (fa: Either) => (fab: Either B>) => Either /** * @since 2.0.0 */ export declare const ap: (fa: Either) => (fab: Either B>) => Either /** * @category instances * @since 2.10.0 */ export declare const Apply: Apply2 /** * @category instances * @since 2.7.0 */ export declare const Applicative: Applicative2 /** * Less strict version of [`chain`](#chain). * * The `W` suffix (short for **W**idening) means that the error types will be merged. * * @example * import * as E from 'fp-ts/Either' * import { pipe } from 'fp-ts/function' * * const e1: E.Either = E.right(1) * const e2: E.Either = E.right(2) * * export const result1 = pipe( * // @ts-expect-error * e1, * E.chain(() => e2) * ) * * // merged error types -----v-------------v * // const result2: E.Either * export const result2 = pipe( * e1, // no error * E.chainW(() => e2) * ) * * @category sequencing * @since 2.6.0 */ export declare const chainW: (f: (a: A) => Either) => (ma: Either) => Either /** * Composes computations in sequence, using the return value of one computation to determine the next computation. * * @category sequencing * @since 2.0.0 */ export declare const chain: (f: (a: A) => Either) => (ma: Either) => Either /** * @category instances * @since 2.10.0 */ export declare const Chain: Chain2 /** * @category instances * @since 2.7.0 */ export declare const Monad: Monad2 /** * Left-associative fold of a structure. * * @example * import { pipe } from 'fp-ts/function' * import * as E from 'fp-ts/Either' * * const startWith = 'prefix' * const concat = (a: string, b: string) => `${a}:${b}` * * assert.deepStrictEqual( * pipe(E.right('a'), E.reduce(startWith, concat)), * 'prefix:a' * ) * * assert.deepStrictEqual( * pipe(E.left('e'), E.reduce(startWith, concat)), * 'prefix' * ) * * @category folding * @since 2.0.0 */ export declare const reduce: (b: B, f: (b: B, a: A) => B) => (fa: Either) => B /** * Map each element of the structure to a monoid, and combine the results. * * @example * import { pipe } from 'fp-ts/function' * import * as E from 'fp-ts/Either' * import * as S from 'fp-ts/string' * * const yell = (a: string) => `${a}!` * * assert.deepStrictEqual( * pipe(E.right('a'), E.foldMap(S.Monoid)(yell)), * 'a!' * ) * * assert.deepStrictEqual( * pipe(E.left('e'), E.foldMap(S.Monoid)(yell)), * S.Monoid.empty * ) * * @category folding * @since 2.0.0 */ export declare const foldMap: (M: Monoid) => (f: (a: A) => M) => (fa: Either) => M /** * Right-associative fold of a structure. * * @example * import { pipe } from 'fp-ts/function' * import * as E from 'fp-ts/Either' * * const startWith = 'postfix' * const concat = (a: string, b: string) => `${a}:${b}` * * assert.deepStrictEqual( * pipe(E.right('a'), E.reduceRight(startWith, concat)), * 'a:postfix' * ) * * assert.deepStrictEqual( * pipe(E.left('e'), E.reduceRight(startWith, concat)), * 'postfix' * ) * * @category folding * @since 2.0.0 */ export declare const reduceRight: (b: B, f: (a: A, b: B) => B) => (fa: Either) => B /** * @category instances * @since 2.7.0 */ export declare const Foldable: Foldable2 /** * Map each element of a structure to an action, evaluate these actions from left to right, and collect the results. * * @example * import { pipe } from 'fp-ts/function' * import * as RA from 'fp-ts/ReadonlyArray' * import * as E from 'fp-ts/Either' * import * as O from 'fp-ts/Option' * * assert.deepStrictEqual( * pipe(E.right(['a']), E.traverse(O.Applicative)(RA.head)), * O.some(E.right('a')) * ) * * assert.deepStrictEqual( * pipe(E.right([]), E.traverse(O.Applicative)(RA.head)), * O.none * ) * * @category traversing * @since 2.6.3 */ export declare const traverse: PipeableTraverse2 /** * Evaluate each monadic action in the structure from left to right, and collect the results. * * @example * import { pipe } from 'fp-ts/function' * import * as E from 'fp-ts/Either' * import * as O from 'fp-ts/Option' * * assert.deepStrictEqual( * pipe(E.right(O.some('a')), E.sequence(O.Applicative)), * O.some(E.right('a')) * ) * * assert.deepStrictEqual( * pipe(E.right(O.none), E.sequence(O.Applicative)), * O.none * ) * * @category traversing * @since 2.6.3 */ export declare const sequence: Traversable2['sequence'] /** * @category instances * @since 2.7.0 */ export declare const Traversable: Traversable2 /** * Map a pair of functions over the two type arguments of the bifunctor. * * @category mapping * @since 2.0.0 */ export declare const bimap: (f: (e: E) => G, g: (a: A) => B) => (fa: Either) => Either /** * Map a function over the first type argument of a bifunctor. * * @category error handling * @since 2.0.0 */ export declare const mapLeft: (f: (e: E) => G) => (fa: Either) => Either /** * @category instances * @since 2.7.0 */ export declare const Bifunctor: Bifunctor2 /** * Less strict version of [`alt`](#alt). * * The `W` suffix (short for **W**idening) means that the error and the return types will be merged. * * @category error handling * @since 2.9.0 */ export declare const altW: (that: Lazy>) => (fa: Either) => Either /** * Identifies an associative operation on a type constructor. It is similar to `Semigroup`, except that it applies to * types of kind `* -> *`. * * In case of `Either` returns the left-most non-`Left` value (or the right-most `Left` value if both values are `Left`). * * | x | y | pipe(x, alt(() => y) | * | -------- | -------- | -------------------- | * | left(a) | left(b) | left(b) | * | left(a) | right(2) | right(2) | * | right(1) | left(b) | right(1) | * | right(1) | right(2) | right(1) | * * @example * import * as E from 'fp-ts/Either' * import { pipe } from 'fp-ts/function' * * assert.deepStrictEqual( * pipe( * E.left('a'), * E.alt(() => E.left('b')) * ), * E.left('b') * ) * assert.deepStrictEqual( * pipe( * E.left('a'), * E.alt(() => E.right(2)) * ), * E.right(2) * ) * assert.deepStrictEqual( * pipe( * E.right(1), * E.alt(() => E.left('b')) * ), * E.right(1) * ) * assert.deepStrictEqual( * pipe( * E.right(1), * E.alt(() => E.right(2)) * ), * E.right(1) * ) * * @category error handling * @since 2.0.0 */ export declare const alt: (that: Lazy>) => (fa: Either) => Either /** * @category instances * @since 2.7.0 */ export declare const Alt: Alt2 /** * @since 2.0.0 */ export declare const extend: (f: (wa: Either) => B) => (wa: Either) => Either /** * @category instances * @since 2.7.0 */ export declare const Extend: Extend2 /** * @category instances * @since 2.7.0 */ export declare const ChainRec: ChainRec2 /** * @since 2.6.3 */ export declare const throwError: MonadThrow2['throwError'] /** * @category instances * @since 2.7.0 */ export declare const MonadThrow: MonadThrow2 /** * @category instances * @since 2.10.0 */ export declare const FromEither: FromEither2 /** * @example * import { fromPredicate, left, right } from 'fp-ts/Either' * import { pipe } from 'fp-ts/function' * * assert.deepStrictEqual( * pipe( * 1, * fromPredicate( * (n) => n > 0, * () => 'error' * ) * ), * right(1) * ) * assert.deepStrictEqual( * pipe( * -1, * fromPredicate( * (n) => n > 0, * () => 'error' * ) * ), * left('error') * ) * * @category lifting * @since 2.0.0 */ export declare const fromPredicate: { (refinement: Refinement, onFalse: (a: A) => E): (a: A) => Either (predicate: Predicate, onFalse: (a: A) => E): (b: B) => Either (predicate: Predicate, onFalse: (a: A) => E): (a: A) => Either } /** * @example * import * as E from 'fp-ts/Either' * import { pipe } from 'fp-ts/function' * import * as O from 'fp-ts/Option' * * assert.deepStrictEqual( * pipe( * O.some(1), * E.fromOption(() => 'error') * ), * E.right(1) * ) * assert.deepStrictEqual( * pipe( * O.none, * E.fromOption(() => 'error') * ), * E.left('error') * ) * * @category conversions * @since 2.0.0 */ export declare const fromOption: (onNone: Lazy) => (fa: Option) => Either /** * Returns `true` if the either is an instance of `Left`, `false` otherwise. * * @category refinements * @since 2.0.0 */ export declare const isLeft: (ma: Either) => ma is Left /** * Returns `true` if the either is an instance of `Right`, `false` otherwise. * * @category refinements * @since 2.0.0 */ export declare const isRight: (ma: Either) => ma is Right /** * Less strict version of [`match`](#match). * * The `W` suffix (short for **W**idening) means that the handler return types will be merged. * * @category pattern matching * @since 2.10.0 */ export declare const matchW: (onLeft: (e: E) => B, onRight: (a: A) => C) => (ma: Either) => B | C /** * Alias of [`matchW`](#matchw). * * @category pattern matching * @since 2.10.0 */ export declare const foldW: (onLeft: (e: E) => B, onRight: (a: A) => C) => (ma: Either) => B | C /** * Takes two functions and an `Either` value, if the value is a `Left` the inner value is applied to the first function, * if the value is a `Right` the inner value is applied to the second function. * * @example * import { match, left, right } from 'fp-ts/Either' * import { pipe } from 'fp-ts/function' * * function onLeft(errors: Array): string { * return `Errors: ${errors.join(', ')}` * } * * function onRight(value: number): string { * return `Ok: ${value}` * } * * assert.strictEqual( * pipe( * right(1), * match(onLeft, onRight) * ), * 'Ok: 1' * ) * assert.strictEqual( * pipe( * left(['error 1', 'error 2']), * match(onLeft, onRight) * ), * 'Errors: error 1, error 2' * ) * * @category pattern matching * @since 2.10.0 */ export declare const match: (onLeft: (e: E) => B, onRight: (a: A) => B) => (ma: Either) => B /** * Alias of [`match`](#match). * * @category pattern matching * @since 2.0.0 */ export declare const fold: (onLeft: (e: E) => B, onRight: (a: A) => B) => (ma: Either) => B /** * Less strict version of [`getOrElse`](#getorelse). * * The `W` suffix (short for **W**idening) means that the handler return type will be merged. * * @category error handling * @since 2.6.0 */ export declare const getOrElseW: (onLeft: (e: E) => B) => (ma: Either) => B | A /** * Returns the wrapped value if it's a `Right` or a default value if is a `Left`. * * @example * import { getOrElse, left, right } from 'fp-ts/Either' * import { pipe } from 'fp-ts/function' * * assert.deepStrictEqual( * pipe( * right(1), * getOrElse(() => 0) * ), * 1 * ) * assert.deepStrictEqual( * pipe( * left('error'), * getOrElse(() => 0) * ), * 0 * ) * * @category error handling * @since 2.0.0 */ export declare const getOrElse: (onLeft: (e: E) => A) => (ma: Either) => A /** * @category mapping * @since 2.10.0 */ export declare const flap: (a: A) => (fab: Either B>) => Either /** * Combine two effectful actions, keeping only the result of the first. * * @since 2.0.0 */ export declare const apFirst: (second: Either) => (first: Either) => Either /** * Less strict version of [`apFirst`](#apfirst) * * The `W` suffix (short for **W**idening) means that the error types will be merged. * * @since 2.12.0 */ export declare const apFirstW: (second: Either) => (first: Either) => Either /** * Combine two effectful actions, keeping only the result of the second. * * @since 2.0.0 */ export declare const apSecond: (second: Either) => (first: Either) => Either /** * Less strict version of [`apSecond`](#apsecond) * * The `W` suffix (short for **W**idening) means that the error types will be merged. * * @since 2.12.0 */ export declare const apSecondW: (second: Either) => (first: Either) => Either /** * Composes computations in sequence, using the return value of one computation to determine the next computation and * keeping only the result of the first. * * @category sequencing * @since 2.0.0 */ export declare const chainFirst: (f: (a: A) => Either) => (ma: Either) => Either /** * Less strict version of [`chainFirst`](#chainfirst) * * The `W` suffix (short for **W**idening) means that the error types will be merged. * * @category sequencing * @since 2.8.0 */ export declare const chainFirstW: ( f: (a: A) => Either ) => (ma: Either) => Either /** * Less strict version of [`flatten`](#flatten). * * The `W` suffix (short for **W**idening) means that the error types will be merged. * * @category sequencing * @since 2.11.0 */ export declare const flattenW: (mma: Either>) => Either /** * The `flatten` function is the conventional monad join operator. It is used to remove one level of monadic structure, projecting its bound argument into the outer level. * * @example * import * as E from 'fp-ts/Either' * * assert.deepStrictEqual(E.flatten(E.right(E.right('a'))), E.right('a')) * assert.deepStrictEqual(E.flatten(E.right(E.left('e'))), E.left('e')) * assert.deepStrictEqual(E.flatten(E.left('e')), E.left('e')) * * @category sequencing * @since 2.0.0 */ export declare const flatten: (mma: Either>) => Either /** * @since 2.0.0 */ export declare const duplicate: (ma: Either) => Either> /** * @category lifting * @since 2.10.0 */ export declare const fromOptionK: ( onNone: Lazy ) => , B>(f: (...a: A) => Option) => (...a: A) => Either /** * @category sequencing * @since 2.11.0 */ export declare const chainOptionK: ( onNone: Lazy ) => (f: (a: A) => Option) => (ma: Either) => Either /** * @example * import * as E from 'fp-ts/Either' * import { pipe } from 'fp-ts/function' * * assert.deepStrictEqual( * pipe( * E.right(1), * E.filterOrElse( * (n) => n > 0, * () => 'error' * ) * ), * E.right(1) * ) * assert.deepStrictEqual( * pipe( * E.right(-1), * E.filterOrElse( * (n) => n > 0, * () => 'error' * ) * ), * E.left('error') * ) * assert.deepStrictEqual( * pipe( * E.left('a'), * E.filterOrElse( * (n) => n > 0, * () => 'error' * ) * ), * E.left('a') * ) * * @category filtering * @since 2.0.0 */ export declare const filterOrElse: { (refinement: Refinement, onFalse: (a: A) => E): (ma: Either) => Either (predicate: Predicate, onFalse: (a: A_1) => E_1): ( mb: Either ) => Either (predicate: Predicate, onFalse: (a: A_2) => E_2): (ma: Either) => Either } /** * Less strict version of [`filterOrElse`](#filterorelse). * * The `W` suffix (short for **W**idening) means that the error types will be merged. * * @category filtering * @since 2.9.0 */ export declare const filterOrElseW: { (refinement: Refinement, onFalse: (a: A) => E2): ( ma: Either ) => Either (predicate: Predicate, onFalse: (a: A) => E2): (mb: Either) => Either (predicate: Predicate, onFalse: (a: A) => E2): (ma: Either) => Either } /** * Returns a `Right` if is a `Left` (and vice versa). * * @since 2.0.0 */ export declare const swap: (ma: Either) => Either /** * Less strict version of [`orElse`](#orelse). * * The `W` suffix (short for **W**idening) means that the return types will be merged. * * @category error handling * @since 2.10.0 */ export declare const orElseW: ( onLeft: (e: E1) => Either ) => (ma: Either) => Either /** * Useful for recovering from errors. * * @category error handling * @since 2.0.0 */ export declare const orElse: (onLeft: (e: E1) => Either) => (ma: Either) => Either /** * Takes a default and a nullable value, if the value is not nully, turn it into a `Right`, if the value is nully use * the provided default as a `Left`. * * @example * import { fromNullable, left, right } from 'fp-ts/Either' * * const parse = fromNullable('nully') * * assert.deepStrictEqual(parse(1), right(1)) * assert.deepStrictEqual(parse(null), left('nully')) * * @category conversions * @since 2.0.0 */ export declare const fromNullable: (e: E) => (a: A) => Either> /** * Constructs a new `Either` from a function that might throw. * * See also [`tryCatchK`](#trycatchk). * * @example * import * as E from 'fp-ts/Either' * * const unsafeHead = (as: ReadonlyArray): A => { * if (as.length > 0) { * return as[0] * } else { * throw new Error('empty array') * } * } * * const head = (as: ReadonlyArray): E.Either => * E.tryCatch(() => unsafeHead(as), e => (e instanceof Error ? e : new Error('unknown error'))) * * assert.deepStrictEqual(head([]), E.left(new Error('empty array'))) * assert.deepStrictEqual(head([1, 2, 3]), E.right(1)) * * @category interop * @since 2.0.0 */ export declare const tryCatch: (f: Lazy, onThrow: (e: unknown) => E) => Either /** * Converts a function that may throw to one returning a `Either`. * * @category interop * @since 2.10.0 */ export declare const tryCatchK: ( f: (...a: A) => B, onThrow: (error: unknown) => E ) => (...a: A) => Either /** * @category lifting * @since 2.9.0 */ export declare const fromNullableK: ( e: E ) => (f: (...a: A) => B | null | undefined) => (...a: A) => Either> /** * @category sequencing * @since 2.9.0 */ export declare const chainNullableK: ( e: E ) => (f: (a: A) => B | null | undefined) => (ma: Either) => Either> /** * @category conversions * @since 2.10.0 */ export declare const toUnion: (fa: Either) => E | A /** * Default value for the `onError` argument of `tryCatch` * * @since 2.0.0 */ export declare function toError(e: unknown): Error /** * @since 2.0.0 */ export declare function elem(E: Eq): { (a: A): (ma: Either) => boolean (a: A, ma: Either): boolean } /** * Returns `false` if `Left` or returns the result of the application of the given predicate to the `Right` value. * * @example * import { exists, left, right } from 'fp-ts/Either' * * const gt2 = exists((n: number) => n > 2) * * assert.strictEqual(gt2(left('a')), false) * assert.strictEqual(gt2(right(1)), false) * assert.strictEqual(gt2(right(3)), true) * * @since 2.0.0 */ export declare const exists: (predicate: Predicate) => (ma: Either) => boolean /** * @category do notation * @since 2.9.0 */ export declare const Do: Either /** * @category do notation * @since 2.8.0 */ export declare const bindTo: ( name: N ) => (fa: Either) => Either declare const let_: ( name: Exclude, f: (a: A) => B ) => (fa: Either) => Either export { /** * @category do notation * @since 2.13.0 */ let_ as let } /** * @category do notation * @since 2.8.0 */ export declare const bind: ( name: Exclude, f: (a: A) => Either ) => (ma: Either) => Either /** * The `W` suffix (short for **W**idening) means that the error types will be merged. * * @category do notation * @since 2.8.0 */ export declare const bindW: ( name: Exclude, f: (a: A) => Either ) => (fa: Either) => Either< E1 | E2, { readonly [K in keyof A | N]: K extends keyof A ? A[K] : B } > /** * @category do notation * @since 2.8.0 */ export declare const apS: ( name: Exclude, fb: Either ) => (fa: Either) => Either /** * Less strict version of [`apS`](#aps). * * The `W` suffix (short for **W**idening) means that the error types will be merged. * * @category do notation * @since 2.8.0 */ export declare const apSW: ( name: Exclude, fb: Either ) => (fa: Either) => Either< E1 | E2, { readonly [K in keyof A | N]: K extends keyof A ? A[K] : B } > /** * @since 2.11.0 */ export declare const ApT: Either /** * Equivalent to `ReadonlyNonEmptyArray#traverseWithIndex(Applicative)`. * * @category traversing * @since 2.11.0 */ export declare const traverseReadonlyNonEmptyArrayWithIndex: ( f: (index: number, a: A) => Either ) => (as: ReadonlyNonEmptyArray) => Either> /** * Equivalent to `ReadonlyArray#traverseWithIndex(Applicative)`. * * @category traversing * @since 2.11.0 */ export declare const traverseReadonlyArrayWithIndex: ( f: (index: number, a: A) => Either ) => (as: readonly A[]) => Either /** * Equivalent to `ReadonlyArray#traverseWithIndex(Applicative)`. * * @category traversing * @since 2.9.0 */ export declare const traverseArrayWithIndex: ( f: (index: number, a: A) => Either ) => (as: ReadonlyArray) => Either> /** * Equivalent to `ReadonlyArray#traverse(Applicative)`. * * @category traversing * @since 2.9.0 */ export declare const traverseArray: ( f: (a: A) => Either ) => (as: readonly A[]) => Either /** * Equivalent to `ReadonlyArray#sequence(Applicative)`. * * @category traversing * @since 2.9.0 */ export declare const sequenceArray: (as: ReadonlyArray>) => Either> /** * Use [`Json`](./Json.ts.html) module instead. * * @category zone of death * @since 2.6.7 * @deprecated */ export declare type Json = boolean | number | string | null | JsonArray | JsonRecord /** * Use [`Json`](./Json.ts.html) module instead. * * @category zone of death * @since 2.6.7 * @deprecated */ export interface JsonRecord { readonly [key: string]: Json } /** * Use [`Json`](./Json.ts.html) module instead. * * @category zone of death * @since 2.6.7 * @deprecated */ export interface JsonArray extends ReadonlyArray {} /** * Use [`parse`](./Json.ts.html#parse) instead. * * @category zone of death * @since 2.0.0 * @deprecated */ export declare function parseJSON(s: string, onError: (reason: unknown) => E): Either /** * Use [`stringify`](./Json.ts.html#stringify) instead. * * @category zone of death * @since 2.0.0 * @deprecated */ export declare const stringifyJSON: (u: unknown, onError: (reason: unknown) => E) => Either /** * This instance is deprecated, use small, specific instances instead. * For example if a function needs a `Functor` instance, pass `E.Functor` instead of `E.either` * (where `E` is from `import E from 'fp-ts/Either'`) * * @category zone of death * @since 2.0.0 * @deprecated */ export declare const either: Monad2 & Foldable2 & Traversable2 & Bifunctor2 & Alt2 & Extend2 & ChainRec2 & MonadThrow2 /** * Use [`getApplySemigroup`](./Apply.ts.html#getapplysemigroup) instead. * * Semigroup returning the left-most `Left` value. If both operands are `Right`s then the inner values * are concatenated using the provided `Semigroup` * * @category zone of death * @since 2.0.0 * @deprecated */ export declare const getApplySemigroup: (S: Semigroup) => Semigroup> /** * Use [`getApplicativeMonoid`](./Applicative.ts.html#getapplicativemonoid) instead. * * @category zone of death * @since 2.0.0 * @deprecated */ export declare const getApplyMonoid: (M: Monoid) => Monoid> /** * Use [`getApplySemigroup`](./Apply.ts.html#getapplysemigroup) instead. * * @category zone of death * @since 2.0.0 * @deprecated */ export declare const getValidationSemigroup: (SE: Semigroup, SA: Semigroup) => Semigroup> /** * Use [`getApplicativeMonoid`](./Applicative.ts.html#getapplicativemonoid) instead. * * @category zone of death * @since 2.0.0 * @deprecated */ export declare const getValidationMonoid: (SE: Semigroup, MA: Monoid) => Monoid> /** * Use [`getApplicativeValidation`](#getapplicativevalidation) and [`getAltValidation`](#getaltvalidation) instead. * * @category zone of death * @since 2.0.0 * @deprecated */ export declare function getValidation( SE: Semigroup ): Monad2C & Foldable2 & Traversable2 & Bifunctor2 & Alt2C & Extend2 & ChainRec2C & MonadThrow2C