recfun: Recursive(ly?) Functional Application State Manager

Recfun can be used to make composable processes.

API

Example

// assuming Node (console) context
var recfun = require('../recfun');
var model = new recfun.Recfun();
model.close(function(){
    // random binary data used as our model
    return "00110";
});
model.close(function(o){
    return o.split("");
});
model.close(function(o){
    return o.map(function(value,index,array){
        return parseInt(value);
    });
});
model.close(function(o){
    return o.map(function(value,index,array){
        return value>0;
    })
});
model.close(function(o){
    console.log(o);
    return o;
});
// toString() logs the recfun object. checkout() hasn't been called yet
// so function return values have not been chached in recfun.states
model.toString()    // => { history:[ [Function], [Function], [Function], 
//                    [Function], [Function] ],
//              states: [],
//              debug: false,
//              checkpoint: 0 }

// run([from]) executes the function chain from beggining to end
// without caching the results. It takes an optional 
// parameter *from* that tells it to start running from a certain 
// point in the function chain this may be useful if you have cached
// some results using checkout().
// the return value is the return value in the last function executed 
// which means that if the last function does NOT return anything, the 
// return value is undefined
model.run();    // => [ false, false, true, false, true ]

// checkout([to]) executes the function chain from beggining to end 
// while caching the results in recfun.states. It takes an optional 
// parameter *to* that tells it to stop executing at a certain point 
// in the function chain. like run() the return value is the return 
// value in the last function executed which means that if the last 
// function does NOT return anything, the return value is undefined
model.checkout()

// if we use toString() again, we see all the changes to the data on 
// the recfun.states array
model.toString() // => {    history:[ 
//                    [Function],[Function],[Function],
//                    [Function],[Function],[Function]
//                   ],
//              states:[ 
//                  '00110',
//                  [ '0', '0', '1', '1', '0' ], 
//                  [ 0, 0, 1, 1, 0 ],
//                  [ false, false, true, true, false ],
//                  [ false, false, true, true, false ]
//                  ],
//              debug: false,
//              checkpoint: 5 }