Created
July 11, 2016 06:03
-
-
Save divanvisagie/e845fa3e76704432e4add9d1970d6446 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 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