/** * A data structure providing "inclusive-or" as opposed to `Either`'s "exclusive-or". * * If you interpret `Either` as suggesting the computation may either fail or succeed (exclusively), then * `These` may fail, succeed, or do both at the same time. * * There are a few ways to interpret the both case: * * - You can think of a computation that has a non-fatal error. * - You can think of a computation that went as far as it could before erroring. * - You can think of a computation that keeps track of errors as it completes. * * Another way you can think of `These` is saying that we want to handle `E` kind of data, `A` kind of data, or * both `E` and `A` kind of data at the same time. This is particularly useful when it comes to displaying UI's. * * (description adapted from https://package.elm-lang.org/packages/joneshf/elm-these) * * Adapted from https://github.com/purescript-contrib/purescript-these * * @since 2.0.0 */ import { Applicative2C } from './Applicative.js'; import { Apply2C } from './Apply.js'; import { Bifunctor2 } from './Bifunctor.js'; import { Chain2C } from './Chain.js'; import { Either, Left, Right } from './Either.js'; import { Eq } from './Eq.js'; import { Foldable2 } from './Foldable.js'; import { FromEither2 } from './FromEither.js'; import { FromThese2 } from './FromThese.js'; import { LazyArg } from './function.js'; import { Functor2 } from './Functor.js'; import { Monad2C } from './Monad.js'; import { MonadThrow2C } from './MonadThrow.js'; import { Monoid } from './Monoid.js'; import { Option } from './Option.js'; import { Pointed2 } from './Pointed.js'; import { Predicate } from './Predicate.js'; import { ReadonlyNonEmptyArray } from './ReadonlyNonEmptyArray.js'; import { Refinement } from './Refinement.js'; import { Semigroup } from './Semigroup.js'; import { Show } from './Show.js'; import { PipeableTraverse2, Traversable2 } from './Traversable.js'; /** * @category model * @since 2.0.0 */ export interface Both { readonly _tag: 'Both'; readonly left: E; readonly right: A; } /** * @category model * @since 2.0.0 */ export type These = Either | Both; /** * Returns `true` if the these is an instance of `Left`, `false` otherwise * * @category refinements * @since 2.0.0 */ export declare const isLeft: (fa: These) => fa is Left; /** * Returns `true` if the these is an instance of `Right`, `false` otherwise * * @category refinements * @since 2.0.0 */ export declare const isRight: (fa: These) => fa is Right; /** * Returns `true` if the these is an instance of `Both`, `false` otherwise * * @category refinements * @since 2.0.0 */ export declare function isBoth(fa: These): fa is Both; /** * @category constructors * @since 2.0.0 */ export declare function left(left: E): These; /** * @category constructors * @since 2.0.0 */ export declare function right(right: A): These; /** * @category constructors * @since 2.0.0 */ export declare function both(left: E, right: A): These; /** * 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, onBoth: (e: E, a: A) => D) => (fa: These) => B | C | D; /** * Alias of [`matchW`](#matchw). * * @category pattern matching * @since 2.10.0 */ export declare const foldW: (onLeft: (e: E) => B, onRight: (a: A) => C, onBoth: (e: E, a: A) => D) => (fa: These) => B | C | D; /** * @category pattern matching * @since 2.10.0 */ export declare const match: (onLeft: (e: E) => B, onRight: (a: A) => B, onBoth: (e: E, a: A) => B) => (fa: These) => B; /** * Alias of [`match`](#match). * * @category pattern matching * @since 2.0.0 */ export declare const fold: (onLeft: (e: E) => B, onRight: (a: A) => B, onBoth: (e: E, a: A) => B) => (fa: These) => B; /** * @since 2.4.0 */ export declare const swap: (fa: These) => These; /** * @category instances * @since 2.0.0 */ export declare function getShow(SE: Show, SA: Show): Show>; /** * @category instances * @since 2.0.0 */ export declare function getEq(EE: Eq, EA: Eq): Eq>; /** * @category instances * @since 2.0.0 */ export declare function getSemigroup(SE: Semigroup, SA: Semigroup): Semigroup>; /** * @category instances * @since 2.10.0 */ export declare const getApply: (S: Semigroup) => Apply2C; /** * @category instances * @since 2.7.0 */ export declare function getApplicative(S: Semigroup): Applicative2C; /** * @category instances * @since 2.10.0 */ export declare function getChain(S: Semigroup): Chain2C; /** * @category instances * @since 2.0.0 */ export declare function getMonad(S: Semigroup): Monad2C & MonadThrow2C; /** * Returns an `E` value if possible * * @example * import { getLeft, left, right, both } from 'fp-ts/These' * import { none, some } from 'fp-ts/Option' * * assert.deepStrictEqual(getLeft(left('a')), some('a')) * assert.deepStrictEqual(getLeft(right(1)), none) * assert.deepStrictEqual(getLeft(both('a', 1)), some('a')) * * @category conversions * @since 2.0.0 */ export declare function getLeft(fa: These): Option; /** * Returns an `A` value if possible * * @example * import { getRight, left, right, both } from 'fp-ts/These' * import { none, some } from 'fp-ts/Option' * * assert.deepStrictEqual(getRight(left('a')), none) * assert.deepStrictEqual(getRight(right(1)), some(1)) * assert.deepStrictEqual(getRight(both('a', 1)), some(1)) * * @category conversions * @since 2.0.0 */ export declare function getRight(fa: These): Option; /** * @example * import { leftOrBoth, left, both } from 'fp-ts/These' * import { none, some } from 'fp-ts/Option' * * assert.deepStrictEqual(leftOrBoth('a')(none), left('a')) * assert.deepStrictEqual(leftOrBoth('a')(some(1)), both('a', 1)) * * @category constructors * @since 2.0.0 */ export declare function leftOrBoth(e: E): (ma: Option) => These; /** * @example * import { rightOrBoth, right, both } from 'fp-ts/These' * import { none, some } from 'fp-ts/Option' * * assert.deepStrictEqual(rightOrBoth(1)(none), right(1)) * assert.deepStrictEqual(rightOrBoth(1)(some('a')), both('a', 1)) * * @category constructors * @since 2.0.0 */ export declare function rightOrBoth(a: A): (me: Option) => These; /** * Returns the `E` value if and only if the value is constructed with `Left` * * @example * import { getLeftOnly, left, right, both } from 'fp-ts/These' * import { none, some } from 'fp-ts/Option' * * assert.deepStrictEqual(getLeftOnly(left('a')), some('a')) * assert.deepStrictEqual(getLeftOnly(right(1)), none) * assert.deepStrictEqual(getLeftOnly(both('a', 1)), none) * * @category conversions * @since 2.0.0 */ export declare function getLeftOnly(fa: These): Option; /** * Returns the `A` value if and only if the value is constructed with `Right` * * @example * import { getRightOnly, left, right, both } from 'fp-ts/These' * import { none, some } from 'fp-ts/Option' * * assert.deepStrictEqual(getRightOnly(left('a')), none) * assert.deepStrictEqual(getRightOnly(right(1)), some(1)) * assert.deepStrictEqual(getRightOnly(both('a', 1)), none) * * @category conversions * @since 2.0.0 */ export declare function getRightOnly(fa: These): Option; /** * Takes a pair of `Option`s and attempts to create a `These` from them * * @example * import { fromOptions, left, right, both } from 'fp-ts/These' * import { none, some } from 'fp-ts/Option' * * assert.deepStrictEqual(fromOptions(none, none), none) * assert.deepStrictEqual(fromOptions(some('a'), none), some(left('a'))) * assert.deepStrictEqual(fromOptions(none, some(1)), some(right(1))) * assert.deepStrictEqual(fromOptions(some('a'), some(1)), some(both('a', 1))) * * @category conversions * @since 2.0.0 */ export declare const fromOptions: (fe: Option, fa: Option) => Option>; /** * 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: These) => These; /** * 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: These) => These; /** * `map` can be used to turn functions `(a: A) => B` into functions `(fa: F) => F` whose argument and return types * use the type constructor `F` to represent some computational context. * * @category mapping * @since 2.0.0 */ export declare const map: (f: (a: A) => B) => (fa: These) => These; /** * @category folding * @since 2.0.0 */ export declare const reduce: (b: B, f: (b: B, a: A) => B) => (fa: These) => B; /** * @category folding * @since 2.0.0 */ export declare const foldMap: (M: Monoid) => (f: (a: A) => M) => (fa: These) => M; /** * @category folding * @since 2.0.0 */ export declare const reduceRight: (b: B, f: (a: A, b: B) => B) => (fa: These) => B; /** * @category traversing * @since 2.6.3 */ export declare const traverse: PipeableTraverse2; /** * @category traversing * @since 2.6.3 */ export declare const sequence: Traversable2['sequence']; /** * @category constructors * @since 2.0.0 */ export declare const of: (right: A) => These; /** * @category type lambdas * @since 2.0.0 */ export declare const URI = "These"; /** * @category type lambdas * @since 2.0.0 */ export type URI = typeof URI; declare module './HKT.js' { interface URItoKind2 { readonly [URI]: These; } } /** * @category instances * @since 2.7.0 */ export declare const Functor: Functor2; /** * @category mapping * @since 2.10.0 */ export declare const flap: (a: A) => (fab: import("./HKT.js").Kind2<"These", E, (a: A) => B>) => import("./HKT.js").Kind2<"These", E, B>; /** * @category instances * @since 2.10.0 */ export declare const Pointed: Pointed2; /** * @category instances * @since 2.7.0 */ export declare const Bifunctor: Bifunctor2; /** * @category instances * @since 2.11.0 */ export declare const FromThese: FromThese2; /** * @category instances * @since 2.7.0 */ export declare const Foldable: Foldable2; /** * @category instances * @since 2.7.0 */ export declare const Traversable: Traversable2; /** * @category instances * @since 2.10.0 */ export declare const FromEither: FromEither2; /** * @category lifting * @since 2.13.0 */ export declare const fromPredicate: { (refinement: Refinement, onFalse: (a: A) => E): (a: A) => These; (predicate: Predicate, onFalse: (a: A) => E): (b: B) => These; (predicate: Predicate, onFalse: (a: A) => E): (a: A) => These; }; /** * @category conversions * @since 2.10.0 */ export declare const fromOption: (onNone: LazyArg) => (fa: Option) => These; /** * @category lifting * @since 2.10.0 */ export declare const fromOptionK: (onNone: LazyArg) => , B>(f: (...a: A) => Option) => (...a: A) => These; /** * @since 2.11.0 */ export declare const elem: (E: Eq) => (a: A) => (ma: These) => boolean; /** * @since 2.11.0 */ export declare const exists: (predicate: Predicate) => (ma: These) => boolean; /** * @example * import { toTuple2, left, right, both } from 'fp-ts/These' * * assert.deepStrictEqual(toTuple2(() => 'a', () => 1)(left('b')), ['b', 1]) * assert.deepStrictEqual(toTuple2(() => 'a', () => 1)(right(2)), ['a', 2]) * assert.deepStrictEqual(toTuple2(() => 'a', () => 1)(both('b', 2)), ['b', 2]) * * @category conversions * @since 2.10.0 */ export declare const toTuple2: (e: LazyArg, a: LazyArg) => (fa: These) => readonly [E, A]; /** * Use [`toTuple2`](#totuple2) instead. * * @category zone of death * @since 2.0.0 * @deprecated */ export declare const toTuple: (e: E, a: A) => ((fa: These) => [E, A]); /** * @since 2.11.0 */ export declare const ApT: These; /** * Equivalent to `ReadonlyNonEmptyArray#traverseWithIndex(getApplicative(S))`. * * @category traversing * @since 2.11.0 */ export declare const traverseReadonlyNonEmptyArrayWithIndex: (S: Semigroup) => (f: (index: number, a: A) => These) => (as: ReadonlyNonEmptyArray) => These>; /** * Equivalent to `ReadonlyArray#traverseWithIndex(getApplicative(S))`. * * @category traversing * @since 2.11.0 */ export declare const traverseReadonlyArrayWithIndex: (S: Semigroup) => (f: (index: number, a: A) => These) => ((as: ReadonlyArray) => These>); /** * This instance is deprecated, use small, specific instances instead. * For example if a function needs a `Functor` instance, pass `T.Functor` instead of `T.these` * (where `T` is from `import T from 'fp-ts/These'`) * * @category zone of death * @since 2.0.0 * @deprecated */ export declare const these: Functor2 & Bifunctor2 & Foldable2 & Traversable2;