@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">
262 lines (215 loc) • 6.18 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.Do = exports.chain = exports.of = exports.map = exports.Right = exports.Left = undefined;
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
exports.inj = inj;
exports.prj = prj;
exports.left = left;
exports.right = right;
exports.isLeft = isLeft;
exports.isRight = isRight;
exports.fromLeft = fromLeft;
exports.fromRight = fromRight;
exports.bimap = bimap;
exports.leftMap = leftMap;
exports.ap = ap;
exports.alt = alt;
exports.extend = extend;
exports.reduce = reduce;
exports.traverse = traverse;
exports.getMonadError = getMonadError;
exports.concat = concat;
exports.getSemigroup = getSemigroup;
exports.either = either;
var _HKT = require('./HKT');
var _Unsafe = require('./Unsafe');
var _Data3 = require('./Data');
var _Identity = require('./Identity');
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var IsEither = function IsEither() {
_classCallCheck(this, IsEither);
};
var Left = exports.Left = function (_Data) {
_inherits(Left, _Data);
function Left() {
_classCallCheck(this, Left);
return _possibleConstructorReturn(this, (Left.__proto__ || Object.getPrototypeOf(Left)).apply(this, arguments));
}
return Left;
}(_Data3.Data1);
var Right = exports.Right = function (_Data2) {
_inherits(Right, _Data2);
function Right() {
_classCallCheck(this, Right);
return _possibleConstructorReturn(this, (Right.__proto__ || Object.getPrototypeOf(Right)).apply(this, arguments));
}
return Right;
}(_Data3.Data1);
function inj(e) {
return e;
}
function prj(fe) {
return fe;
}
function left(left) {
return inj(new Left(left));
}
function right(right) {
return inj(new Right(right));
}
function isLeft(e) {
return prj(e) instanceof Left;
}
function isRight(e) {
return prj(e) instanceof Right;
}
function fromLeft(flr) {
var lr = prj(flr);
if (lr instanceof Right) {
throw new Error('fromLeft returned a Right');
}
return lr.value0;
}
function fromRight(flr) {
var lr = prj(flr);
if (lr instanceof Left) {
throw new Error('fromRight returned a Left');
}
return lr.value0;
}
function _map(f, fa) {
var a = prj(fa);
if (a instanceof Left) {
return (0, _Unsafe.unsafeCoerce)(a);
}
return right(f(a.value0));
}
exports.map = _map;
function bimap(f, g, fac) {
var ac = prj(fac);
if (ac instanceof Left) {
return left(f(ac.value0));
}
return right(g(ac.value0));
}
function leftMap(f, e) {
return either.bimap(f, _Identity.id, e);
}
function ap(fab, fa) {
var ab = prj(fab);
if (ab instanceof Left) {
return (0, _Unsafe.unsafeCoerce)(ab);
}
return _map(ab.value0, fa);
}
var _of = right;
exports.of = _of;
function _chain(f, fa) {
var a = prj(fa);
if (a instanceof Left) {
return (0, _Unsafe.unsafeCoerce)(fa);
}
return f(a.value0);
}
exports.chain = _chain;
function alt(fx, fy) {
if (prj(fx) instanceof Left) {
return fy;
}
return fx;
}
function extend(f, ea) {
return prj(ea) instanceof Left ? (0, _Unsafe.unsafeCoerce)(ea) : right(f(ea));
}
function reduce(f, b, fa) {
var a = prj(fa);
if (a instanceof Left) {
return b;
}
return f(b, a.value0);
}
function traverse(applicative, f, ta) {
var a = prj(ta);
if (a instanceof Left) {
return applicative.of((0, _Unsafe.unsafeCoerce)(ta));
}
return applicative.map(_of, f(a.value0));
}
function getMonadError() {
return {
of: _of,
map: _map,
ap: ap,
chain: _chain,
throwError: function throwError(e) {
return left(e);
},
catchError: function catchError(ma, handler) {
return either(handler, right, ma);
}
};
}
function concat(semigroup) {
return function concat(fx, fy) {
var x = prj(fx);
var y = prj(fy);
if (x instanceof Right && y instanceof Right) {
return right(semigroup.concat(x.value0, y.value0));
}
return fx;
};
}
function getSemigroup(semigroup) {
return {
concat: concat(semigroup)
};
}
function either(f, g, fa) {
var a = prj(fa);
if (a instanceof Left) {
return f(a.value0);
}
return g(a.value0);
}
var Do = exports.Do = function () {
_createClass(Do, null, [{
key: 'of',
value: function of(a) {
return new Do(_of(a));
}
}]);
function Do(value) {
_classCallCheck(this, Do);
this.value = value;
}
_createClass(Do, [{
key: 'map',
value: function map(f) {
return new Do(_map(f, this.value));
}
}, {
key: 'chain',
value: function chain(f) {
return new Do(_chain(f, this.value));
}
}]);
return Do;
}();
if (false) {
// eslint-disable-line
({
map: _map,
ap: ap,
of: _of,
chain: _chain,
bimap: bimap,
alt: alt,
extend: extend,
reduce: reduce,
traverse: traverse
});
}