UNPKG

@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">

85 lines (68 loc) 1.47 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); exports.asks = undefined; exports.inj = inj; exports.prj = prj; exports.runReader = runReader; exports.ask = ask; exports.local = local; exports.map = map; exports.ap = ap; exports.of = of; exports.chain = chain; var _HKT = require('./HKT'); var _Fun = require('./Fun'); var _Identity = require('./Identity'); function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } var IsReader = function IsReader() { _classCallCheck(this, IsReader); }; function inj(a) { return a; } function prj(fa) { return fa; } function runReader(r, e) { return prj(r)(e); } // reads the current context function ask() { return inj(_Identity.id); } var asks = exports.asks = inj; // changes the value of the local context during the execution of the action `fa` function local(f, fa) { return inj(function (e) { return runReader(fa, f(e)); }); } function map(f, fa) { return inj((0, _Fun.compose)(f, prj(fa))); } function ap(fab, fa) { return chain(function (f) { return map(f, fa); }, fab); // <= derived } function of(a) { return inj(function () { return a; }); } function chain(f, fa) { return inj(function (e) { return prj(f(runReader(fa, e)))(e); }); } if (false) { // eslint-disable-line ({ map: map, ap: ap, of: of, chain: chain }); }