Skip to content

Instantly share code, notes, and snippets.

@ruxo
Created August 4, 2015 07:04
Show Gist options
  • Select an option

  • Save ruxo/5e2f87dc6c34c2bd78b2 to your computer and use it in GitHub Desktop.

Select an option

Save ruxo/5e2f87dc6c34c2bd78b2 to your computer and use it in GitHub Desktop.
[sketch] Promise as functor in Javascript
var Promise__map = function(g){ // g: a -> b
var _f = function(){};
var h = function(f){ // h : (b -> c) -> 0
_f = f;
};
this.fp(function(a){
var b = g(a);
_f(b);
return b;
});
return Promise(h);
}
var Promise = function(fp){ // fp : (a -> b) -> 0
return { fp: fp, subscribe: Promise__map };
};
x = []
function async(f) { x.push(f); }
p = Promise(async);
p1 = p.subscribe(function(n) { return "Number = " + n; });
p2 = p1.subscribe(console.log.bind(console));
x[0](123);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment