Skip to content

Instantly share code, notes, and snippets.

@aereal
Last active December 9, 2015 05:41
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 aereal/8e5203f57db6ee04cd5b to your computer and use it in GitHub Desktop.
Save aereal/8e5203f57db6ee04cd5b to your computer and use it in GitHub Desktop.
class MP<T> extends Promise<T> {
filter<T>(pred: (v: T) => boolean): MP<T> {
return this.then((v) => { return pred(v) ? v : new Error() })
}
}
function filter<T>(promise: Promise<T>, pred: (v: T) => boolean): Promise<T> {
return promise.then((v) => {
return pred(v) ? v : new Error('Promise cannot satisfy precondition');
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment