Last active
December 11, 2015 04:58
-
-
Save juandopazo/4548886 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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