@dillonkearns/elm-graphql
Version:
<img src="https://cdn.jsdelivr.net/gh/martimatix/logo-graphqelm/logo.svg" alt="dillonearns/elm-graphql logo" width="40%" align="right">
98 lines (76 loc) • 1.91 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.prj = prj;
exports.inj = inj;
exports.composeFunctor = composeFunctor;
exports.composeApplicative = composeApplicative;
exports.composeFoldable = composeFoldable;
exports.composeTraversable = composeTraversable;
var _HKT = require('./HKT');
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
/*
Functor, Applicative, Foldable, and Traversable are all closed under composition
(Monad is not)
*/
var IsCompose = function IsCompose() {
_classCallCheck(this, IsCompose);
}; // eslint-disable-line no-unused-vars
function prj(fga) {
return fga;
}
function inj(fga) {
return fga;
}
function composeFunctor(f, g) {
function map(h, fga) {
return inj(f.map(function (ga) {
return g.map(h, ga);
}, prj(fga)));
}
return {
map: map
};
}
function composeApplicative(f, g) {
var _composeFunctor = composeFunctor(f, g),
map = _composeFunctor.map;
function ap(fgab, fga) {
return inj(f.ap(f.map(function (h) {
return function (ga) {
return g.ap(h, ga);
};
}, prj(fgab)), prj(fga)));
}
function of(a) {
return inj(f.of(g.of(a)));
}
return {
map: map,
ap: ap,
of: of
};
}
function composeFoldable(f1, f2) {
function reduce(f, b, fa) {
return f1.reduce(function (a, gb) {
return f2.reduce(f, a, gb);
}, b, prj(fa));
}
return {
reduce: reduce
};
}
function composeTraversable(t1, t2) {
function traverse(applicative, f, ta) {
return applicative.map(inj, t1.traverse(applicative, function (t2a) {
return t2.traverse(applicative, f, t2a);
}, prj(ta)));
}
return {
map: composeFunctor(t1, t2).map,
reduce: composeFoldable(t1, t2).reduce,
traverse: traverse
};
}