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

71 lines (53 loc) 1.42 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); exports.inj = inj; exports.prj = prj; exports.runYoneda = runYoneda; exports.liftYoneda = liftYoneda; exports.lowerYoneda = lowerYoneda; exports.map = map; 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"); } } /* The Yoneda `Functor` `Yoneda f` is a `Functor` for any type constructor `f`. Implementation based on the purescript-free package (https://github.com/purescript/purescript-free) */ var IsYoneda = function IsYoneda() { _classCallCheck(this, IsYoneda); }; function inj(a) { return a; } function prj(fa) { return fa; } /* Run a computation of type `Yoneda f a`. */ function runYoneda(y, f) { return prj(y)(f); } /* Lift a value described by the `Functor` `f` to the `Functor` `Yoneda f`. */ function liftYoneda(functor, fa) { return inj(function (k) { return functor.map(k, fa); }); } /* Lower a value of type `Yoneda f a` to the type constructor `f`. */ function lowerYoneda(y) { return runYoneda(y, _Identity.id); } function map(f, y) { return inj(function (k) { return runYoneda(y, (0, _Fun.compose)(k, f)); }); } if (false) { // eslint-disable-line ({ map: map }); }