@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">
47 lines (38 loc) • 1.08 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.modify = modify;
exports.composeIso = composeIso;
exports.asLens = asLens;
exports.asPrism = asPrism;
var _Either = require('./Either');
var either = _interopRequireWildcard(_Either);
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(iso, f, s) {
return iso.reverseGet(f(iso.get(s)));
}
function composeIso(abcd, stab) {
return {
get: function get(s) {
return abcd.get(stab.get(s));
},
reverseGet: function reverseGet(d) {
return stab.reverseGet(abcd.reverseGet(d));
}
};
}
function asLens(iso) {
return {
get: iso.get,
set: iso.reverseGet
};
}
function asPrism(iso) {
return {
getOrModify: function getOrModify(s) {
return either.right(iso.get(s));
},
reverseGet: iso.reverseGet
};
}