Pair
Pair:
object
Defined in: Core/Pair.ts:22
Type Declaration
Section titled “Type Declaration”first: <
A,B>(pair) =>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
Pair.second to retrieve the second value.
Example
Section titled “Example”make: <
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) => (pair) =>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”(first) => C
onSecond
Section titled “onSecond”(second) => D
Returns
Section titled “Returns”(pair) => Pair<C, D>
- Pair.mapFirst to transform only the first element.
- Pair.mapSecond to transform only the second element.
Example
Section titled “Example”mapFirst
Section titled “mapFirst”mapFirst: <
A,C>(transform) => <B>(pair) =>Pair<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>(pair) => Pair<C, B>
- Pair.mapSecond to transform the second element instead.
- Pair.mapBoth to transform both elements at once.
Example
Section titled “Example”mapSecond
Section titled “mapSecond”mapSecond: <
B,D>(transform) => <A>(pair) =>Pair<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>(pair) => Pair<A, D>
- Pair.mapFirst to transform the first element instead.
- Pair.mapBoth to transform both elements at once.
Example
Section titled “Example”merge: <
A,B,C>(transform) => (pair) =>C
Applies a binary function to both values, merging 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”transform
Section titled “transform”(first, second) => C
Returns
Section titled “Returns”(pair) => C
Example
Section titled “Example”second
Section titled “second”second: <
A,B>(pair) =>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
Pair.first to retrieve the first value.
Example
Section titled “Example”swap: <
A,B>(pair) =>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>(sideEffect) => (pair) =>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”sideEffect
Section titled “sideEffect”(first, second) => void
Returns
Section titled “Returns”(pair) => Pair<A, B>
Example
Section titled “Example”to:
object
to.array
Section titled “to.array”array: <
A,B>(pair) => 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)[]