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

62 lines (50 loc) 1.44 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); exports.set = set; exports.choice = choice; exports.composeSetter = composeSetter; exports.fromFunctor = fromFunctor; var _HKT = require('./HKT'); 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; } } /* A [[PSetter]] is a generalisation of Functor map: - `map: (A => B) => F[A] => F[B]` - `modify: (A => B) => S => T` */ function set(setter, b, s) { return setter.modify(function () { return b; }, s); } /** join two PSetter with the same target */ function choice(setter1, setter2) { return { modify: function modify(f, s) { return either.either(function (s1) { return either.left(setter1.modify(f, s1)); }, function (s2) { return either.right(setter2.modify(f, s2)); }, s); } }; } function composeSetter(abcd, stab) { return { modify: function modify(f, s) { return stab.modify(function (c) { return abcd.modify(f, c); }, s); } }; } function fromFunctor(functor) { return { modify: function modify(f, s) { return functor.map(f, s); } }; }