The Y-combinator is one of most beautiful ideas in all of programming. This code demonstrates how amazingly powerful the simple ideas of functional programming are. The Y-Combinator is a higher order function. It accepts a single argument, which is a function that isn't recursive. It returns a copy of the function which is recursive. It requires that our language supports first class functions and that functions be named or anonymous. Go supports all of that.
Ever wonder the Y in the Y-Combinator comes from?
See how A and B and C connect the dots to form the top part of the "y"?
The diagram below illustrates how the Y-Combinator works:
The following are the steps to wire up the Y-Combinator:
f(newData)
callsBase64ToByes
with thebase64
encoded text.dString
is downcast into a string.
- The
return func(e error) (Data, error) {
statement is executed and returns execution back to the return statement in theNext
function.
- At that time,
f...