Skip to content

Instantly share code, notes, and snippets.

@juandopazo
Last active December 11, 2015 04:58
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 juandopazo/4548886 to your computer and use it in GitHub Desktop.
Save juandopazo/4548886 to your computer and use it in GitHub Desktop.
// Inherit from Y.Promise as you would from any other class
function ListPromise() {
ListPromise.superclass.constructor.apply(this, arguments);
}
Y.extend(ListPromise, Y.Promise, {
map: function (fn, context) {
return this.then(function (values) {
return Y.Array.map(values, fn, context);
});
},
filter: function (fn, context) {
return this.then(function (values) {
return Y.Array.filter(values, fn, context);
});
}
});
var list = new ListPromise(function (resolve) {
// this is not async, but it's just an example
resolve([1, 2, 3]);
});
list.map(function (x) {
return x * x;
}).filter(function (x) {
return x > 3;
}).then(function (values) {
console.log(values); // [14, 9]
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment