This is my current code:
const fn = parameter => {
// if, else ...
fn(X);
};
fn(0);
Now, I can\'t use this approach as I need to cal
If you want to call recursive an lambda expression
or anonymous function
you need Y combinator. For more details you can read http://mvanier.livejournal.com/2897.html
For factorial it is like
var Y = (proc) => {
return ((x) => {
return proc((y) => { return (x(x))(y);});
})((x) => {
return proc((y) => { return (x(x))(y);});
});
};
var factorial = (fact) => {
return (n) => {
return (n === 0) ? 1 : n * fact(n-1);
};
};
console.log( Y(factorial)(5) );
For you code it will be like
const fn = (func)=> {
return (parameter) => {
// if else
func(X);
}
};
Y(fn)(0);