In an earlier post I wrote about a way to implement `cons`

,
`car`

and `cdr`

(also known as `pair`

, `first`

, and `second`

) using
only function definitions and if statements in javascript. That was
pretty mindblowing for me, but it turns out there is an a way to do
*without even using branching logic*.

The pair function take to arguments X and Y, and returns another function which takes a function argument S. It is essentially a promise to apply S to X and Y.

Implementing `first`

and `second`

becomes pretty straightforward; it’s
just a matter of taking the output from a call to `pair`

and applying
it to a function taking two arguments X and Y and returns either X
(`first`

) or Y (`second`

).

The CoffeeScript implementation is incredibly terse and elegant, reading almost like mathematical notation.