Last active
December 9, 2015 05:41
-
-
Save aereal/8e5203f57db6ee04cd5b 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
class MP<T> extends Promise<T> { | |
filter<T>(pred: (v: T) => boolean): MP<T> { | |
return this.then((v) => { return pred(v) ? v : new Error() }) | |
} | |
} |
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
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