Created
November 14, 2021 23:33
-
-
Save kraftdorian/8896e1c59deba7f323b60d9cccd5840b to your computer and use it in GitHub Desktop.
TypeScript Promise functor
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 PromiseFunctor<In, Out>(f: (input: In) => Out, value: Promise<In>): Promise<Out> { | |
return value.then<Out>( | |
a => f(a) | |
); | |
} | |
// ==== TEST ==== | |
const x = 1; | |
const p = Promise.resolve(x); | |
PromiseFunctor(y => String(y), p) | |
.then(y => { | |
console.log(y === x.toString()) | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment