Skip to main content

These

Instances​

Constructors​

Conversions​

Error handling​

Folding​

Lifting​

Mapping​

Model​

Pattern matching​

Refinements​

Traversing​

Type lambdas​

Utilities​

Instances​

Bifunctor​

Signature​

export declare const Bifunctor: Bifunctor2<URI>

Details​

  • Added in 0.1.0

License​

  • MIT – Copyright (c) 2017-present Giulio Canti

Foldable​

Signature​

export declare const Foldable: Foldable2<URI>

Details​

  • Added in 0.1.0

License​

  • MIT – Copyright (c) 2017-present Giulio Canti

FromEither​

Signature​

export declare const FromEither: FromEither2<URI>

Details​

  • Added in 0.1.0

License​

  • MIT – Copyright (c) 2017-present Giulio Canti

FromThese​

Signature​

export declare const FromThese: FromThese2<URI>

Details​

  • Added in 0.1.0

License​

  • MIT – Copyright (c) 2017-present Giulio Canti

Functor​

Signature​

export declare const Functor: Functor2<URI>

Details​

  • Added in 0.1.0

License​

  • MIT – Copyright (c) 2017-present Giulio Canti

Pointed​

Signature​

export declare const Pointed: Pointed2<URI>

Details​

  • Added in 0.1.0

License​

  • MIT – Copyright (c) 2017-present Giulio Canti

Traversable​

Signature​

export declare const Traversable: Traversable2<URI>

Details​

  • Added in 0.1.0

License​

  • MIT – Copyright (c) 2017-present Giulio Canti

getApplicative​

Signature​

export declare function getApplicative<E>(S: Semigroup<E>): Applicative2C<URI, E>

Details​

  • Added in 0.1.0

License​

  • MIT – Copyright (c) 2017-present Giulio Canti

getApply​

Signature​

export declare const getApply: <E>(S: Semigroup<E>) => Apply2C<'These', E>

Details​

  • Added in 0.1.0

License​

  • MIT – Copyright (c) 2017-present Giulio Canti

getChain​

Signature​

export declare function getChain<E>(S: Semigroup<E>): Chain2C<URI, E>

Details​

  • Added in 0.1.0

License​

  • MIT – Copyright (c) 2017-present Giulio Canti

getEq​

Signature​

export declare function getEq<E, A>(EE: Eq<E>, EA: Eq<A>): Eq<These<E, A>>

Details​

  • Added in 0.1.0

License​

  • MIT – Copyright (c) 2017-present Giulio Canti

getMonad​

Signature​

export declare function getMonad<E>(S: Semigroup<E>): Monad2C<URI, E> & MonadThrow2C<URI, E>

Details​

  • Added in 0.1.0

License​

  • MIT – Copyright (c) 2017-present Giulio Canti

getSemigroup​

Signature​

export declare function getSemigroup<E, A>(SE: Semigroup<E>, SA: Semigroup<A>): Semigroup<These<E, A>>

Details​

  • Added in 0.1.0

License​

  • MIT – Copyright (c) 2017-present Giulio Canti

getShow​

Signature​

export declare function getShow<E, A>(SE: Show<E>, SA: Show<A>): Show<These<E, A>>

Details​

  • Added in 0.1.0

License​

  • MIT – Copyright (c) 2017-present Giulio Canti

Constructors​

both​

Signature​

export declare function both<E, A>(left: E, right: A): These<E, A>

Details​

  • Added in 0.1.0

License​

  • MIT – Copyright (c) 2017-present Giulio Canti

left​

Signature​

export declare function left<E = never, A = never>(left: E): These<E, A>

Details​

  • Added in 0.1.0

License​

  • MIT – Copyright (c) 2017-present Giulio Canti

leftOrBoth​

Signature​

export declare function leftOrBoth<E>(e: E): <A>(ma: Option<A>) => These<E, A>

Details​

  • Added in 0.1.0

Example​

import { leftOrBoth, left, both } from '@fp-tx/core/These'
import { none, some } from '@fp-tx/core/Option'

assert.deepStrictEqual(leftOrBoth('a')(none), left('a'))
assert.deepStrictEqual(leftOrBoth('a')(some(1)), both('a', 1))

License​

  • MIT – Copyright (c) 2017-present Giulio Canti

of​

Signature​

export declare const of: <E = never, A = never>(right: A) => These<E, A>

Details​

  • Added in 0.1.0

License​

  • MIT – Copyright (c) 2017-present Giulio Canti

Signature​

export declare function right<E = never, A = never>(right: A): These<E, A>

Details​

  • Added in 0.1.0

License​

  • MIT – Copyright (c) 2017-present Giulio Canti

rightOrBoth​

Signature​

export declare function rightOrBoth<A>(a: A): <E>(me: Option<E>) => These<E, A>

Details​

  • Added in 0.1.0

Example​

import { rightOrBoth, right, both } from '@fp-tx/core/These'
import { none, some } from '@fp-tx/core/Option'

assert.deepStrictEqual(rightOrBoth(1)(none), right(1))
assert.deepStrictEqual(rightOrBoth(1)(some('a')), both('a', 1))

License​

  • MIT – Copyright (c) 2017-present Giulio Canti

Conversions​

fromOption​

Signature​

export declare const fromOption: <E>(onNone: LazyArg<E>) => <A>(fa: Option<A>) => These<E, A>

Details​

  • Added in 0.1.0

License​

  • MIT – Copyright (c) 2017-present Giulio Canti

fromOptions​

Takes a pair of Options and attempts to create a These from them

Signature​

export declare const fromOptions: <E, A>(fe: Option<E>, fa: Option<A>) => Option<These<E, A>>

Details​

  • Added in 0.1.0

Example​

import { fromOptions, left, right, both } from '@fp-tx/core/These'
import { none, some } from '@fp-tx/core/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)))

License​

  • MIT – Copyright (c) 2017-present Giulio Canti

getLeft​

Returns an E value if possible

Signature​

export declare function getLeft<E, A>(fa: These<E, A>): Option<E>

Details​

  • Added in 0.1.0

Example​

import { getLeft, left, right, both } from '@fp-tx/core/These'
import { none, some } from '@fp-tx/core/Option'

assert.deepStrictEqual(getLeft(left('a')), some('a'))
assert.deepStrictEqual(getLeft(right(1)), none)
assert.deepStrictEqual(getLeft(both('a', 1)), some('a'))

License​

  • MIT – Copyright (c) 2017-present Giulio Canti

getLeftOnly​

Returns the E value if and only if the value is constructed with Left

Signature​

export declare function getLeftOnly<E, A>(fa: These<E, A>): Option<E>

Details​

  • Added in 0.1.0

Example​

import { getLeftOnly, left, right, both } from '@fp-tx/core/These'
import { none, some } from '@fp-tx/core/Option'

assert.deepStrictEqual(getLeftOnly(left('a')), some('a'))
assert.deepStrictEqual(getLeftOnly(right(1)), none)
assert.deepStrictEqual(getLeftOnly(both('a', 1)), none)

License​

  • MIT – Copyright (c) 2017-present Giulio Canti

getRight​

Returns an A value if possible

Signature​

export declare function getRight<E, A>(fa: These<E, A>): Option<A>

Details​

  • Added in 0.1.0

Example​

import { getRight, left, right, both } from '@fp-tx/core/These'
import { none, some } from '@fp-tx/core/Option'

assert.deepStrictEqual(getRight(left('a')), none)
assert.deepStrictEqual(getRight(right(1)), some(1))
assert.deepStrictEqual(getRight(both('a', 1)), some(1))

License​

  • MIT – Copyright (c) 2017-present Giulio Canti

getRightOnly​

Returns the A value if and only if the value is constructed with Right

Signature​

export declare function getRightOnly<E, A>(fa: These<E, A>): Option<A>

Details​

  • Added in 0.1.0

Example​

import { getRightOnly, left, right, both } from '@fp-tx/core/These'
import { none, some } from '@fp-tx/core/Option'

assert.deepStrictEqual(getRightOnly(left('a')), none)
assert.deepStrictEqual(getRightOnly(right(1)), some(1))
assert.deepStrictEqual(getRightOnly(both('a', 1)), none)

License​

  • MIT – Copyright (c) 2017-present Giulio Canti

toTuple2​

Signature​

export declare const toTuple2: <E, A>(e: LazyArg<E>, a: LazyArg<A>) => (fa: These<E, A>) => readonly [E, A]

Details​

  • Added in 0.1.0

Example​

import { toTuple2, left, right, both } from '@fp-tx/core/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],
)

License​

  • MIT – Copyright (c) 2017-present Giulio Canti

Error handling​

mapLeft​

Map a function over the first type argument of a bifunctor.

Signature​

export declare const mapLeft: <E, G>(f: (e: E) => G) => <A>(fa: These<E, A>) => These<G, A>

Details​

  • Added in 0.1.0

License​

  • MIT – Copyright (c) 2017-present Giulio Canti

Folding​

foldMap​

Signature​

export declare const foldMap: <M>(M: Monoid<M>) => <A>(f: (a: A) => M) => <E>(fa: These<E, A>) => M

Details​

  • Added in 0.1.0

License​

  • MIT – Copyright (c) 2017-present Giulio Canti

reduce​

Signature​

export declare const reduce: <A, B>(b: B, f: (b: B, a: A) => B) => <E>(fa: These<E, A>) => B

Details​

  • Added in 0.1.0

License​

  • MIT – Copyright (c) 2017-present Giulio Canti

reduceRight​

Signature​

export declare const reduceRight: <A, B>(b: B, f: (a: A, b: B) => B) => <E>(fa: These<E, A>) => B

Details​

  • Added in 0.1.0

License​

  • MIT – Copyright (c) 2017-present Giulio Canti

Lifting​

fromOptionK​

Signature​

export declare const fromOptionK: <E>(
onNone: LazyArg<E>,
) => <A extends ReadonlyArray<unknown>, B>(f: (...a: A) => Option<B>) => (...a: A) => These<E, B>

Details​

  • Added in 0.1.0

License​

  • MIT – Copyright (c) 2017-present Giulio Canti

fromPredicate​

Signature​

export declare const fromPredicate: {
<A, B extends A, E>(refinement: Refinement<A, B>, onFalse: (a: A) => E): (a: A) => These<E, B>
<A, E>(predicate: Predicate<A>, onFalse: (a: A) => E): <B extends A>(b: B) => These<E, B>
<A, E>(predicate: Predicate<A>, onFalse: (a: A) => E): (a: A) => These<E, A>
}

Details​

  • Added in 0.1.0

License​

  • MIT – Copyright (c) 2017-present Giulio Canti

Mapping​

bimap​

Map a pair of functions over the two type arguments of the bifunctor.

Signature​

export declare const bimap: <E, G, A, B>(f: (e: E) => G, g: (a: A) => B) => (fa: These<E, A>) => These<G, B>

Details​

  • Added in 0.1.0

License​

  • MIT – Copyright (c) 2017-present Giulio Canti

flap​

Signature​

export declare const flap: <A>(a: A) => <E, B>(fab: These<E, (a: A) => B>) => These<E, B>

Details​

  • Added in 0.1.0

License​

  • MIT – Copyright (c) 2017-present Giulio Canti

map​

map can be used to turn functions (a: A) => B into functions (fa: F<A>) => F<B> whose argument and return types use the type constructor F to represent some computational context.

Signature​

export declare const map: <A, B>(f: (a: A) => B) => <E>(fa: These<E, A>) => These<E, B>

Details​

  • Added in 0.1.0

License​

  • MIT – Copyright (c) 2017-present Giulio Canti

Model​

Both​

Signature​

export interface Both<E, A> {
readonly _tag: 'Both'
readonly left: E
readonly right: A
}

Details​

  • Added in 0.1.0

License​

  • MIT – Copyright (c) 2017-present Giulio Canti

These​

Signature​

export type These<E, A> = Either<E, A> | Both<E, A>

Details​

  • Added in 0.1.0

License​

  • MIT – Copyright (c) 2017-present Giulio Canti

Pattern matching​

fold​

Alias of match.

Signature​

export declare const fold: <E, A, B>(
onLeft: (e: E) => B,
onRight: (a: A) => B,
onBoth: (e: E, a: A) => B,
) => (fa: These<E, A>) => B

Details​

  • Added in 0.1.0

License​

  • MIT – Copyright (c) 2017-present Giulio Canti

foldW​

Alias of matchW.

Signature​

export declare const foldW: <E, B, A, C, D>(
onLeft: (e: E) => B,
onRight: (a: A) => C,
onBoth: (e: E, a: A) => D,
) => (fa: These<E, A>) => B | C | D

Details​

  • Added in 0.1.0

License​

  • MIT – Copyright (c) 2017-present Giulio Canti

match​

Signature​

export declare const match: <E, A, B>(
onLeft: (e: E) => B,
onRight: (a: A) => B,
onBoth: (e: E, a: A) => B,
) => (fa: These<E, A>) => B

Details​

  • Added in 0.1.0

License​

  • MIT – Copyright (c) 2017-present Giulio Canti

matchW​

Less strict version of match.

The W suffix (short for Widening) means that the handler return types will be merged.

Signature​

export declare const matchW: <E, B, A, C, D>(
onLeft: (e: E) => B,
onRight: (a: A) => C,
onBoth: (e: E, a: A) => D,
) => (fa: These<E, A>) => B | C | D

Details​

  • Added in 0.1.0

License​

  • MIT – Copyright (c) 2017-present Giulio Canti

Refinements​

isBoth​

Returns true if the these is an instance of Both, false otherwise

Signature​

export declare function isBoth<E, A>(fa: These<E, A>): fa is Both<E, A>

Details​

  • Added in 0.1.0

License​

  • MIT – Copyright (c) 2017-present Giulio Canti

isLeft​

Returns true if the these is an instance of Left, false otherwise

Signature​

export declare const isLeft: <E>(fa: These<E, unknown>) => fa is Left<E>

Details​

  • Added in 0.1.0

License​

  • MIT – Copyright (c) 2017-present Giulio Canti

isRight​

Returns true if the these is an instance of Right, false otherwise

Signature​

export declare const isRight: <A>(fa: These<unknown, A>) => fa is Right<A>

Details​

  • Added in 0.1.0

License​

  • MIT – Copyright (c) 2017-present Giulio Canti

Traversing​

sequence​

Signature​

export declare const sequence: Traversable2<URI>['sequence']

Details​

  • Added in 0.1.0

License​

  • MIT – Copyright (c) 2017-present Giulio Canti

traverse​

Signature​

export declare const traverse: PipeableTraverse2<URI>

Details​

  • Added in 0.1.0

License​

  • MIT – Copyright (c) 2017-present Giulio Canti

traverseReadonlyArrayWithIndex​

Equivalent to ReadonlyArray#traverseWithIndex(getApplicative(S)).

Signature​

export declare const traverseReadonlyArrayWithIndex: <E>(
S: Semigroup<E>,
) => <A, B>(f: (index: number, a: A) => These<E, B>) => (as: readonly A[]) => These<E, readonly B[]>

Details​

  • Added in 0.1.0

License​

  • MIT – Copyright (c) 2017-present Giulio Canti

traverseReadonlyNonEmptyArrayWithIndex​

Equivalent to ReadonlyNonEmptyArray#traverseWithIndex(getApplicative(S)).

Signature​

export declare const traverseReadonlyNonEmptyArrayWithIndex: <E>(
S: Semigroup<E>,
) => <A, B>(
f: (index: number, a: A) => These<E, B>,
) => (as: ReadonlyNonEmptyArray<A>) => These<E, ReadonlyNonEmptyArray<B>>

Details​

  • Added in 0.1.0

License​

  • MIT – Copyright (c) 2017-present Giulio Canti

Type lambdas​

URI​

Signature​

export type URI = typeof URI

Details​

  • Added in 0.1.0

License​

  • MIT – Copyright (c) 2017-present Giulio Canti

URI​

Signature​

export declare const URI = 'These'

Details​

  • Added in 0.1.0

License​

  • MIT – Copyright (c) 2017-present Giulio Canti

Utilities​

ApT​

Signature​

export declare const ApT: These<never, readonly []>

Details​

  • Added in 0.1.0

License​

  • MIT – Copyright (c) 2017-present Giulio Canti

elem​

Signature​

export declare const elem: <A>(E: Eq<A>) => (a: A) => <E>(ma: These<E, A>) => boolean

Details​

  • Added in 0.1.0

License​

  • MIT – Copyright (c) 2017-present Giulio Canti

exists​

Signature​

export declare const exists: <A>(predicate: Predicate<A>) => (ma: These<unknown, A>) => boolean

Details​

  • Added in 0.1.0

License​

  • MIT – Copyright (c) 2017-present Giulio Canti

swap​

Signature​

export declare const swap: <E, A>(fa: These<E, A>) => These<A, E>

Details​

  • Added in 0.1.0

License​

  • MIT – Copyright (c) 2017-present Giulio Canti

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')

Signature​

export declare const these: Functor2<URI> & Bifunctor2<URI> & Foldable2<URI> & Traversable2<URI>

Details​

  • Added in 0.1.0
  • Deprecated

License​

  • MIT – Copyright (c) 2017-present Giulio Canti

toTuple​

Use toTuple2 instead.

Signature​

export declare const toTuple: <E, A>(e: E, a: A) => (fa: These<E, A>) => [E, A]

Details​

  • Added in 0.1.0
  • Deprecated

License​

  • MIT – Copyright (c) 2017-present Giulio Canti