Z Combinator for self-referencing anonymous functions
Master build: [![Master branch build status][travis-master]][travis]
Develop build: [![Master branch build status][travis-develop]][travis]
This library provides a utility function to support the creation of self-referencing anonymous functions.
It can be installed in whichever way you prefer, but I recommend [NPM][npm].
var z = require'z-combinator';// Factorialvar factorial = zreturnreturn 2 >= n ? n : n * fnn - 1;;factorial2 // => 2factorial3 // => 6factorial4 // => 24factorial5 // => 120
Just as you would with any other recursive function, make sure you include some sort of break condition. If you miss it out, the function will recur indefinitely.
var z = require'z-combinator';zreturnreturn fnn + 1; // <= Unconditional recursion;0;// => Error: Maximum call stack exceededzreturnreturn 100 <= n ? n : fnn + 1; // <= Conditional recursion;0;// => 100
I accept contributions to the source via Pull Request, but passing unit tests must be included before it will be considered for merge.
$ make install$ make tests
If you have [Vagrant][vagrant] installed, you can build the dev environment to assist development.
The repository will be mounted in
$ vagrant up$ vagrant sshWelcome to Ubuntu 12.04 LTS (GNU/Linux 3.2.0-23-generic x86_64)$ cd /srv
The content of this library is released under the MIT License by Andrew Lawson.
You can find a copy of this license at http://www.opensource.org/licenses/mit or in [