somewhat adapted for node.js; more fp-sugar