Skip to content

Instantly share code, notes, and snippets.

@briancavalier
Created March 26, 2014 19:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save briancavalier/9791127 to your computer and use it in GitHub Desktop.
Save briancavalier/9791127 to your computer and use it in GitHub Desktop.
Simple promise.fold usage example
// Should log:
// 3
// Bob
// b
var when = require('when');
when.resolve(1).fold(sum, 2).done(console.log);
when.resolve({ name: 'Bob' }).fold(get, 'name').done(console.log);
when.resolve(['a', 'b', 'c']).fold(get, 1).done(console.log);
function sum(x, y) {
return x + y;
}
function get(k, o) {
return o[k];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment