Get the first element of the pair (car
)
pair
Pair<A, B>
const pair = cons(5, 'hello');
car(pair); // 5
Returns A
Get the second element of the pair (cdr
)
pair
Pair<A, B>
const pair = cons(5, 'hello');
cdr(pair); // hello
Returns B
Pair constructor (cons
)
a
Ab
B
const pair = cons(5, 'hello');
const pair = cons(cons(1, null), 'world');
Returns Pair<A, B>
Check if the passed argument is a pair (isPair
)
cons
Pair<A, B>
const pair = cons(5, 'hello');
isPair(pair); // true
isPair(5); // false
Returns boolean
Convert a pair to a string (toString
)
pair
Pair<A, B>
toString(cons('', 10)); // "('', 10)"
toString(cons('one', 'two')); // "('one', 'two')"
Returns string