Skip to content

Instantly share code, notes, and snippets.

@divanvisagie
Created July 11, 2016 06:03
Show Gist options
  • Save divanvisagie/e845fa3e76704432e4add9d1970d6446 to your computer and use it in GitHub Desktop.
Save divanvisagie/e845fa3e76704432e4add9d1970d6446 to your computer and use it in GitHub Desktop.
class Future<A> {
constructor(public promise: Promise<A>) { }
static value<A>(arg: A) {
return new Future(
new Promise<A>(resolve => resolve(arg))
)
}
map(callback: (p: A) => any): Future<any> {
const prom = new Promise<any>((resolve, reject) => {
this.promise.then(x => {
resolve(callback(x))
});
});
return new Future(prom)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment