Pair
Pair:
object
Defined in: Core/Pair.ts:23
Type Declaration
Section titled “Type Declaration”first: <
A,B>(p) =>A
Returns the first value from the pair.
Type Parameters
Section titled “Type Parameters”A
B
Parameters
Section titled “Parameters”Pair<A, B>
Returns
Section titled “Returns”A
Example
Section titled “Example”fold: <
A,B,C>(f) => (p) =>C
Applies a binary function to both values, collapsing the pair into a single value. Useful as the final step when consuming a pair in a pipeline.
Type Parameters
Section titled “Type Parameters”A
B
C
Parameters
Section titled “Parameters”(a, b) => C
Returns
Section titled “Returns”(p) => C
Example
Section titled “Example”from:
object
from.array
Section titled “from.array”array: <
A,B>(arr) =>Pair<A,B> =makeArray
Creates a Pair from a two-element array.
Type Parameters
Section titled “Type Parameters”A
B
Parameters
Section titled “Parameters”readonly [A, B]
Returns
Section titled “Returns”Pair<A, B>
Example
Section titled “Example”from.pair
Section titled “from.pair”pair: <
A,B>(first,second) =>Pair<A,B> =makePair
Creates a Pair from two values.
Type Parameters
Section titled “Type Parameters”A
B
Parameters
Section titled “Parameters”A
second
Section titled “second”B
Returns
Section titled “Returns”Pair<A, B>
Example
Section titled “Example”mapBoth
Section titled “mapBoth”mapBoth: <
A,C,B,D>(onFirst,onSecond) => (p) =>Pair<C,D>
Transforms both values independently in a single step.
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”(p) => Pair<C, D>
Example
Section titled “Example”mapFirst
Section titled “mapFirst”mapFirst: <
A,C>(f) => <B>(p) =>Pair<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>(p) => Pair<C, B>
Example
Section titled “Example”mapSecond
Section titled “mapSecond”mapSecond: <
B,D>(f) => <A>(p) =>Pair<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>(p) => Pair<A, D>
Example
Section titled “Example”second
Section titled “second”second: <
A,B>(p) =>B
Returns the second value from the pair.
Type Parameters
Section titled “Type Parameters”A
B
Parameters
Section titled “Parameters”Pair<A, B>
Returns
Section titled “Returns”B
Example
Section titled “Example”swap: <
A,B>(p) =>Pair<B,A>
Swaps the two values: [A, B] becomes [B, A].
Type Parameters
Section titled “Type Parameters”A
B
Parameters
Section titled “Parameters”Pair<A, B>
Returns
Section titled “Returns”Pair<B, A>
Example
Section titled “Example”tap: <
A,B>(f) => (p) =>Pair<A,B>
Runs a side effect with both values without changing the pair. Useful for logging or debugging in the middle of a pipeline.
Type Parameters
Section titled “Type Parameters”A
B
Parameters
Section titled “Parameters”(a, b) => void
Returns
Section titled “Returns”(p) => Pair<A, B>
Example
Section titled “Example”to:
object
to.Array
Section titled “to.Array”Array: <
A,B>(p) => readonly (A|B)[]
Converts the pair to a heterogeneous readonly array readonly (A | B)[].
Type Parameters
Section titled “Type Parameters”A
B
Parameters
Section titled “Parameters”Pair<A, B>
Returns
Section titled “Returns”readonly (A | B)[]