A Pair is another way of storing two values in a single value. Elements of a Pair do not need to be of the same type
Implements: BiFunctor
, Monad
, Semigroup
, Setoid
Pair constructor
Param | Type | Description |
---|---|---|
v1 | any |
First element of the Pair |
v2 | any |
second element of the Pair |
Pair constructor
Param | Type | Description |
---|---|---|
v | any |
Element that will be stored as first and second element of the Pair |
Check if the values of the current pair is equal to the values of the passed Pair. Pairs are equal only if the first and second values of both Pairs are equal
Param | Type | Description |
---|---|---|
j | Pair |
The Pair to compare with |
Concat the current pair with the passed one. Note that both first and second elements of the Pair should be of type semigroup for cancat to work
Param | Type | Description |
---|---|---|
p | Pair |
Pair to concat |
Get the first element of the Pair
Get the second element of the Pair
Applies the function inside the second element of the passed Pair to the current Pair and concats the first element of the second Pair to the first element of the current Pair
Param | Type | Description |
---|---|---|
j | Pair |
Pair with function as the second element |
Get the values within the Pair as an Array of length 2
Apply the function to the second element of the current Pair
Param | Type | Description |
---|---|---|
f | function |
Function |
Apply f1 to the first element and f2 to the second element of the current Pair
Param | Type | Description |
---|---|---|
f1 | function |
Function to be applied on the first element |
f2 | function |
Function to be applied on the second element |
Chain together many computations that return a Pair
Param | Type | Description |
---|---|---|
f | function |
Function that returns another Pair |
Swap the elements of the current pair
Get a stringified version of the Pair
Lets construct some Pairs
import {Pair} from "fp-kudojs";
const point1 = Pair(1, 2);
console.log(point1.toString()); // Pair((1), (2))
const point2 = Pair.of(2);
console.log(point2.toString()); // Pair((2), (2))
Two Pairs are equal if the first and the second element of each Pair are equal
console.log(point1.equals(Pair(1,2))) //true
console.log(point2.equals(point1) //false
console.log(Pair([1], [2]).equals(Pair([1],[2]))) //false
Concat Pairs. Note that to concat pairs the elements of each Pair should be semigroups of the same type
const p1 = Pair([1], [2]);
const p2 = Pair([3], [4]);
const p3 = p1.concat(p2);
console.log(p3.getValue()); // [[1, 3], [2, 4]]
** TODO: Add more examples **