These
These:
object
Defined in: Core/These.ts:26
Type Declaration
Section titled “Type Declaration”chainFirst
Section titled “chainFirst”chainFirst: <
A,B,C>(f) => (data) =>These<C,B>
Chains These computations by passing the first value to f. Second propagates unchanged; First and Both apply f to the first value.
Type Parameters
Section titled “Type Parameters”A
B
C
Parameters
Section titled “Parameters”(a) => These<C, B>
Returns
Section titled “Returns”(data) => These<C, B>
Example
Section titled “Example”chainSecond
Section titled “chainSecond”chainSecond: <
A,B,D>(f) => (data) =>These<A,D>
Chains These computations by passing the second value to f. First propagates unchanged; Second and Both apply f to the second value.
Type Parameters
Section titled “Type Parameters”A
B
D
Parameters
Section titled “Parameters”(b) => These<A, D>
Returns
Section titled “Returns”(data) => These<A, D>
Example
Section titled “Example”fold: <
A,B,C>(onFirst,onSecond,onBoth) => (data) =>C
Extracts a value from a These by providing handlers for all three cases.
Type Parameters
Section titled “Type Parameters”A
B
C
Parameters
Section titled “Parameters”onFirst
Section titled “onFirst”(a) => C
onSecond
Section titled “onSecond”(b) => C
onBoth
Section titled “onBoth”(a, b) => C
Returns
Section titled “Returns”(data) => C
Example
Section titled “Example”getFirstOrElse
Section titled “getFirstOrElse”getFirstOrElse: <
A,C>(defaultValue) => <B>(data) =>A|C
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”A
C
Parameters
Section titled “Parameters”defaultValue
Section titled “defaultValue”() => C
Returns
Section titled “Returns”<B>(data) => A | C
Example
Section titled “Example”getSecondOrElse
Section titled “getSecondOrElse”getSecondOrElse: <
B,D>(defaultValue) => <A>(data) =>B|D
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”B
D
Parameters
Section titled “Parameters”defaultValue
Section titled “defaultValue”() => D
Returns
Section titled “Returns”<A>(data) => B | D
Example
Section titled “Example”hasFirst
Section titled “hasFirst”hasFirst: <
A,B>(data) => data is TheseFirst<A> | TheseBoth<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”data is TheseFirst<A> | TheseBoth<A, B>
Example
Section titled “Example”hasSecond
Section titled “hasSecond”hasSecond: <
A,B>(data) => data is TheseSecond<B> | TheseBoth<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”data is TheseSecond<B> | TheseBoth<A, B>
Example
Section titled “Example”is:
object
is.both
Section titled “is.both”both: <
A,B>(data) =>data is TheseBoth<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”data is TheseBoth<A, B>
Example
Section titled “Example”is.first
Section titled “is.first”first: <
A,B>(data) =>data is TheseFirst<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”data is TheseFirst<A>
Example
Section titled “Example”is.second
Section titled “is.second”second: <
A,B>(data) =>data is TheseSecond<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”data is TheseSecond<B>
Example
Section titled “Example”make:
object
make.both
Section titled “make.both”both: <
A,B>(f,s) =>TheseBoth<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
B
Returns
Section titled “Returns”TheseBoth<A, B>
Example
Section titled “Example”make.first
Section titled “make.first”first: <
A>(value) =>TheseFirst<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”TheseFirst<A>
Example
Section titled “Example”make.second
Section titled “make.second”second: <
B>(value) =>TheseSecond<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”TheseSecond<B>
Example
Section titled “Example”mapBoth
Section titled “mapBoth”mapBoth: <
A,C,B,D>(onFirst,onSecond) => (data) =>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”(a) => C
onSecond
Section titled “onSecond”(b) => D
Returns
Section titled “Returns”(data) => These<C, D>
Example
Section titled “Example”mapFirst
Section titled “mapFirst”mapFirst: <
A,C>(f) => <B>(data) =>These<C,B>
Transforms the first value, leaving the second unchanged.
Type Parameters
Section titled “Type Parameters”A
C
Parameters
Section titled “Parameters”(a) => C
Returns
Section titled “Returns”<B>(data) => These<C, B>
Example
Section titled “Example”mapSecond
Section titled “mapSecond”mapSecond: <
B,D>(f) => <A>(data) =>These<A,D>
Transforms the second value, leaving the first unchanged.
Type Parameters
Section titled “Type Parameters”B
D
Parameters
Section titled “Parameters”(b) => D
Returns
Section titled “Returns”<A>(data) => These<A, D>
Example
Section titled “Example”match: <
A,B,C>(cases) => (data) =>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”(a, b) => C
(a) => C
second
Section titled “second”(b) => C
Returns
Section titled “Returns”(data) => C
Example
Section titled “Example”swap: <
A,B>(data) =>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”tap: <
A>(f) => <B>(data) =>These<A,B>
Runs a side effect on the first value without changing the These. Useful for logging or debugging.
Type Parameters
Section titled “Type Parameters”A
Parameters
Section titled “Parameters”(a) => void
Returns
Section titled “Returns”<B>(data) => These<A, B>