@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">
72 lines (57 loc) • 1.89 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.modify = undefined;
exports.asFold = asFold;
exports.asSetter = asSetter;
exports.composeTraversal = composeTraversal;
exports.fromTraversable = fromTraversable;
var _HKT = require('./HKT');
var _Const = require('./Const');
var _Identity = require('./Identity');
var id = _interopRequireWildcard(_Identity);
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
function _modify(traversal, f, s) {
return id.extract(traversal.modifyF(id, function (a) {
return id.of(f(a));
}, s));
}
/*
A Traversal is the generalisation of an Optional to several targets.
In other word, a Traversal allows to focus from a type S into 0 to n values of type A.
The most common example of a Traversal would be to focus into all elements inside of a container (e.g. List, Maybe).
*/
exports.modify = _modify;
function asFold(traversal) {
return {
foldMap: function foldMap(monoid, f, s) {
return (0, _Const.prj)(traversal.modifyF((0, _Const.getApplicative)(monoid), function (a) {
return (0, _Const.inj)(f(a));
}, s));
}
};
}
function asSetter(traversal) {
return {
modify: function modify(f, s) {
return _modify(traversal, f, s);
}
};
}
function composeTraversal(ab, st) {
return {
modifyF: function modifyF(applicative, f, s) {
return st.modifyF(applicative, function (c) {
return ab.modifyF(applicative, f, c);
}, s);
}
};
}
function fromTraversable(traversable) {
return {
modifyF: function modifyF(applicative, f, s) {
return traversable.traverse(applicative, f, s);
}
};
}