Skip to content

Instantly share code, notes, and snippets.

@dmitry-vsl
Created January 17, 2015 01:42
Show Gist options
  • Save dmitry-vsl/af101ffc8a619d53c119 to your computer and use it in GitHub Desktop.
Save dmitry-vsl/af101ffc8a619d53c119 to your computer and use it in GitHub Desktop.
/* @flow */
// http://flowtype.org/
class DumbPromise<T>{
value: T;
constructor(value:T){
this.value = value;
};
then<Y>(f:(x:T)=>Y): DumbPromise<Y> {
return new DumbPromise(f(this.value));
};
}
new DumbPromise(1)
.then(x => x.toString())
.then(x => x.toLowerCase())
.then(x => x.length)
// next line contains type error
.then(x => x.toLowerCase())
;
@glaznaj
Copy link

glaznaj commented Jan 29, 2015

And Scala:

    class DumbPromise[T](value: T) {
        def then[Y](f: T => Y) = new DumbPromise(f(value))
    }

    new DumbPromise(1)
    .then(_.toString)
    .then(_.toLowerCase)
    .then(_.length)
    //.then(_.toLowerCase) This line contains type error

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment