UNPKG

tco

Version:

Tail call optimization in Node

28 lines (19 loc) 529 B
"use strict"; module.exports = tco; function tco(f) { console.log('enter tco fun'); // XXX if (typeof f == 'function') { var tf = function () { var nf = f, na = arguments, next = true; while (1) { var r = nf.apply(null, na); nf = r[0].tco; na = r[1]; } }; tf.tco = f; return tf; } else { throw new Error('tco() expects a function'); } }