In an earlier post I wrote about a way to implement
cdr (also known as
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.
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 (
The CoffeeScript implementation is incredibly terse and elegant, reading almost like mathematical notation.