fantasy-frees
Version:
Free yourself in the land of fantasies.
32 lines (25 loc) • 632 B
JavaScript
var combinators = require('fantasy-combinators'),
daggy = require('daggy'),
compose = combinators.compose,
identity = combinators.identity,
Yoneda = daggy.tagged('f');
Yoneda.lift = function(x) {
return Yoneda(function(y) {
return x.map(y);
});
};
Yoneda.prototype.map = function(f) {
var self = this;
return Yoneda(function(x) {
return self.run(compose(x)(f));
});
};
Yoneda.prototype.lower = function() {
return this.f(identity);
};
Yoneda.prototype.run = function(k) {
return this.f(k);
};
// Export
if (typeof module != 'undefined')
module.exports = Yoneda;