These
These:
object
Defined in: Core/These.ts:28
Type Declaration
Section titled “Type Declaration”chainFirst
Section titled “chainFirst”chainFirst: <
A,C,B2>(transform) => <B1>(these) =>These<C,B2|B1>
Chains These computations by passing the first value to transform. Second propagates unchanged; First and Both apply transform to the first value.
Type Parameters
Section titled “Type Parameters”A
C
B2 = never
Parameters
Section titled “Parameters”transform
Section titled “transform”(first) => These<C, B2>
Returns
Section titled “Returns”<B1>(these) => These<C, B2 | B1>
These.chainSecond to chain based on the second value.
Example
Section titled “Example”chainSecond
Section titled “chainSecond”chainSecond: <
B,D,A2>(transform) => <A1>(these) =>These<A2|A1,D>
Chains These computations by passing the second value to transform. First propagates unchanged; Second and Both apply transform to the second value.
Type Parameters
Section titled “Type Parameters”B
D
A2 = never
Parameters
Section titled “Parameters”transform
Section titled “transform”(second) => These<A2, D>
Returns
Section titled “Returns”<A1>(these) => These<A2 | A1, D>
These.chainFirst to chain based on the first value.
Example
Section titled “Example”from:
object
from.Pair
Section titled “from.Pair”Pair: <
A,B>(pair) =>Both<A,B>
Creates a These.Both holding both values of a Pair.
Type Parameters
Section titled “Type Parameters”A
B
Parameters
Section titled “Parameters”Pair<A, B>
Returns
Section titled “Returns”Both<A, B>
These.to.Pair to extract a Pair from a These when both values are present.
Example
Section titled “Example”getFirstOrElse
Section titled “getFirstOrElse”getFirstOrElse: <
C>(fallback) => <A,B>(these) =>C|A
Returns the first value, or a default if the These has no first value.
The default can be a different type, widening the result to A | C.
Type Parameters
Section titled “Type Parameters”C
Parameters
Section titled “Parameters”fallback
Section titled “fallback”() => C
Returns
Section titled “Returns”<A, B>(these) => C | A
These.getSecondOrElse to retrieve the second value with fallback.
Example
Section titled “Example”getSecondOrElse
Section titled “getSecondOrElse”getSecondOrElse: <
D>(fallback) => <B,A>(these) =>D|B
Returns the second value, or a default if the These has no second value.
The default can be a different type, widening the result to B | D.
Type Parameters
Section titled “Type Parameters”D
Parameters
Section titled “Parameters”fallback
Section titled “fallback”() => D
Returns
Section titled “Returns”<B, A>(these) => D | B
These.getFirstOrElse to retrieve the first value with fallback.
Example
Section titled “Example”hasFirst
Section titled “hasFirst”hasFirst: <
A,B>(these) => these is First<A> | Both<A, B>
Returns true if the These contains a first value (First or Both).
Type Parameters
Section titled “Type Parameters”A
B
Parameters
Section titled “Parameters”These<A, B>
Returns
Section titled “Returns”these is First<A> | Both<A, B>
These.hasSecond to check if These contains a second value.
Example
Section titled “Example”hasSecond
Section titled “hasSecond”hasSecond: <
A,B>(these) => these is Second<B> | Both<A, B>
Returns true if the These contains a second value (Second or Both).
Type Parameters
Section titled “Type Parameters”A
B
Parameters
Section titled “Parameters”These<A, B>
Returns
Section titled “Returns”these is Second<B> | Both<A, B>
These.hasFirst to check if These contains a first value.
Example
Section titled “Example”is:
object
is.both
Section titled “is.both”both: <
A,B>(these) =>these is Both<A, B>=isBoth
Type guard — checks if a These holds both values simultaneously.
Type Parameters
Section titled “Type Parameters”A
B
Parameters
Section titled “Parameters”These<A, B>
Returns
Section titled “Returns”these is Both<A, B>
Example
Section titled “Example”is.first
Section titled “is.first”first: <
A,B>(these) =>these is First<A>=isFirst
Type guard — checks if a These holds only a first value.
Type Parameters
Section titled “Type Parameters”A
B
Parameters
Section titled “Parameters”These<A, B>
Returns
Section titled “Returns”these is First<A>
Example
Section titled “Example”is.second
Section titled “is.second”second: <
A,B>(these) =>these is Second<B>=isSecond
Type guard — checks if a These holds only a second value.
Type Parameters
Section titled “Type Parameters”A
B
Parameters
Section titled “Parameters”These<A, B>
Returns
Section titled “Returns”these is Second<B>
Example
Section titled “Example”make:
object
make.both
Section titled “make.both”both: <
A,B>(first,second) =>Both<A,B> =makeBoth
Creates a These holding both a first and a second value simultaneously.
Type Parameters
Section titled “Type Parameters”A
B
Parameters
Section titled “Parameters”A
second
Section titled “second”B
Returns
Section titled “Returns”Both<A, B>
Example
Section titled “Example”make.first
Section titled “make.first”first: <
A>(value) =>First<A> =makeFirst
Creates a These holding only a first value.
Type Parameters
Section titled “Type Parameters”A
Parameters
Section titled “Parameters”A
Returns
Section titled “Returns”First<A>
Example
Section titled “Example”make.second
Section titled “make.second”second: <
B>(value) =>Second<B> =makeSecond
Creates a These holding only a second value.
Type Parameters
Section titled “Type Parameters”B
Parameters
Section titled “Parameters”B
Returns
Section titled “Returns”Second<B>
Example
Section titled “Example”mapBoth
Section titled “mapBoth”mapBoth: <
A,C,B,D>(onFirst,onSecond) => (these) =>These<C,D>
Transforms both the first and second values independently.
Type Parameters
Section titled “Type Parameters”A
C
B
D
Parameters
Section titled “Parameters”onFirst
Section titled “onFirst”(first) => C
onSecond
Section titled “onSecond”(second) => D
Returns
Section titled “Returns”(these) => These<C, D>
- These.mapFirst to transform only the first element.
- These.mapSecond to transform only the second element.
Example
Section titled “Example”mapFirst
Section titled “mapFirst”mapFirst: <
A,C>(transform) => <B>(these) =>These<C,B>
Transforms the first value, leaving the second unchanged.
Type Parameters
Section titled “Type Parameters”A
C
Parameters
Section titled “Parameters”transform
Section titled “transform”(first) => C
Returns
Section titled “Returns”<B>(these) => These<C, B>
- These.mapSecond to transform the second element.
- These.mapBoth to transform both elements.
Example
Section titled “Example”mapSecond
Section titled “mapSecond”mapSecond: <
B,D>(transform) => <A>(these) =>These<A,D>
Transforms the second value, leaving the first unchanged.
Type Parameters
Section titled “Type Parameters”B
D
Parameters
Section titled “Parameters”transform
Section titled “transform”(second) => D
Returns
Section titled “Returns”<A>(these) => These<A, D>
- These.mapFirst to transform the first element.
- These.mapBoth to transform both elements.
Example
Section titled “Example”match: <
A,B,C>(cases) => (these) =>C
Pattern matches on a These, returning the result of the matching case.
Type Parameters
Section titled “Type Parameters”A
B
C
Parameters
Section titled “Parameters”(first, second) => C
(first) => C
second
Section titled “second”(second) => C
Returns
Section titled “Returns”(these) => C
Example
Section titled “Example”swap: <
A,B>(these) =>These<B,A>
Swaps the roles of first and second values.
- First(a) → Second(a)
- Second(b) → First(b)
- Both(a, b) → Both(b, a)
Type Parameters
Section titled “Type Parameters”A
B
Parameters
Section titled “Parameters”These<A, B>
Returns
Section titled “Returns”These<B, A>
Example
Section titled “Example”tapBoth
Section titled “tapBoth”tapBoth: <
A,B>(sideEffect) => (these) =>These<A,B>
Runs a side effect on both values when both are present simultaneously (Both variant only).
Type Parameters
Section titled “Type Parameters”A
B
Parameters
Section titled “Parameters”sideEffect
Section titled “sideEffect”(first, second) => void
Returns
Section titled “Returns”(these) => These<A, B>
- These.tapFirst to run a side effect on the first value.
- These.tapSecond to run a side effect on the second value.
Example
Section titled “Example”tapFirst
Section titled “tapFirst”tapFirst: <
A>(sideEffect) => <B>(these) =>These<A,B>
Runs a side effect on the first value (if present in First or Both) without changing the These. Useful for logging or debugging.
Type Parameters
Section titled “Type Parameters”A
Parameters
Section titled “Parameters”sideEffect
Section titled “sideEffect”(first) => void
Returns
Section titled “Returns”<B>(these) => These<A, B>
- These.tapSecond to run a side effect on the second value instead.
- These.tapBoth to run a side effect on both values when both are present.
Example
Section titled “Example”tapSecond
Section titled “tapSecond”tapSecond: <
B>(sideEffect) => <A>(these) =>These<A,B>
Runs a side effect on the second value (if present in Second or Both) without changing the These. Useful for logging or reporting warnings.
Type Parameters
Section titled “Type Parameters”B
Parameters
Section titled “Parameters”sideEffect
Section titled “sideEffect”(second) => void
Returns
Section titled “Returns”<A>(these) => These<A, B>
- These.tapFirst to run a side effect on the first value instead.
- These.tapBoth to run a side effect on both values when both are present.
Example
Section titled “Example”to:
object
to.Pair
Section titled “to.Pair”Converts a These to a Maybe containing a Pair if both values are present. Returns Some([first, second]) for Both; returns None for First and Second.
Type Parameters
Section titled “Type Parameters”A
B
Parameters
Section titled “Parameters”These<A, B>
Returns
Section titled “Returns”These.from.Pair to create a These.Both from a Pair.