UNPKG

fp-ts-wonka

Version:

[fp-ts](https://github.com/gcanti/fp-ts) bindings for [wonka](https://wonka.kitten.sh/)

540 lines 14.2 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.chainFirstW = exports.chainFirst = exports.Chain = exports.Applicative = exports.Apply = exports.Pointed = exports.flap = exports.Functor = exports.URI = exports.throwError = exports.fromPredicate = exports.fromOption = exports.fromEither = exports.filterOrElse = exports.of = exports.flatten = exports.chain = exports.chainW = exports.mapLeft = exports.bimap = exports.alt = exports.apSecond = exports.apFirst = exports.ap = exports.map = exports.swap = exports.orLeft = exports.orElseFirstW = exports.orElseFirst = exports.orElseW = exports.orElse = exports.getOrElseW = exports.getOrElse = exports.foldW = exports.matchEW = exports.fold = exports.matchE = exports.matchW = exports.match = exports.fromSource = exports.fromTask = exports.fromIO = exports.fromTaskEither = exports.leftIO = exports.rightIO = exports.fromIOEither = exports.leftSource = exports.rightSource = exports.right = exports.left = void 0; exports.toTaskEither = exports.apSW = exports.apS = exports.bindW = exports.bind = exports.bindTo = exports.Do = exports.MonadThrow = exports.MonadSource = exports.MonadTask = exports.MonadIO = exports.Alt = exports.Bifunctor = exports.Monad = void 0; var Apply_1 = require("fp-ts/Apply"); var E = __importStar(require("fp-ts/Either")); var ET = __importStar(require("fp-ts/EitherT")); var function_1 = require("fp-ts/function"); var Functor_1 = require("fp-ts/Functor"); var Chain_1 = require("fp-ts/Chain"); var S = __importStar(require("./Source")); // ------------------------------------------------------------------------------------- // constructors // ------------------------------------------------------------------------------------- /** * @since 0.1.0 * @category Constructors */ exports.left = /*#__PURE__*/ ET.left(S.Pointed); /** * @since 0.1.0 * @category Constructors */ exports.right = /*#__PURE__*/ ET.right(S.Pointed); /** * @since 0.1.0 * @category Constructors */ exports.rightSource = /*#__PURE__*/ S.map(E.right); /** * @since 0.1.0 * @category Constructors */ exports.leftSource = /*#__PURE__*/ S.map(E.left); // ------------------------------------------------------------------------------------- // natural transformations // ------------------------------------------------------------------------------------- /** * @since 0.1.0 * @category Natural transformations */ exports.fromIOEither = S.fromIO; /** * @since 0.1.0 * @category Natural transformations */ exports.rightIO = /*#__PURE__*/ (0, function_1.flow)(S.fromIO, exports.rightSource); /** * @since 0.1.0 * @category Natural transformations */ exports.leftIO = /*#__PURE__*/ (0, function_1.flow)(S.fromIO, exports.leftSource); /** * @since 0.1.0 * @category Natural transformations */ exports.fromTaskEither = S.fromTask; /** * @since 0.1.0 * @category Natural transformations */ exports.fromIO = exports.rightIO; /** * @since 0.1.0 * @category Natural transformations */ exports.fromTask = /*#__PURE__*/ (0, function_1.flow)(S.fromTask, exports.rightSource); /** * @since 0.1.0 * @category Natural transformations */ exports.fromSource = exports.rightSource; // ------------------------------------------------------------------------------------- // destructors // ------------------------------------------------------------------------------------- /** * @since 0.1.0 * @category Destructors */ exports.match = /*#__PURE__*/ (0, function_1.flow)(E.fold, S.chain); /** * Less strict version of [`match`](#match). * * @since 0.1.0 * @category Destructors */ exports.matchW = exports.match; /** * @since 0.1.0 * @category Destructors */ exports.matchE = /*#__PURE__*/ ET.matchE(S.Monad); /** * Alias of [`matchE`](#matche). * * @since 0.1.0 * @category Destructors */ exports.fold = exports.matchE; /** * Less strict version of [`matchE`](#matche). * * @since 0.1.0 * @category Destructors */ exports.matchEW = exports.matchE; /** * Alias of [`matchW`](#matchW). * * @since 0.1.0 * @category Destructors */ exports.foldW = exports.matchEW; /** * @since 0.1.0 * @category Destructors */ exports.getOrElse = ET.getOrElse(S.Monad); /** * Less strict version of [`getOrElse`](#getorelse). * * @since 0.1.0 * @category Destructors */ exports.getOrElseW = exports.getOrElse; // ------------------------------------------------------------------------------------- // combinators // ------------------------------------------------------------------------------------- /** * @since 0.1.0 * @category Combinators */ exports.orElse = ET.orElse(S.Monad); /** * Less strict version of [`orElse`](#orelse). * * @since 0.1.0 * @category Combinators */ exports.orElseW = exports.orElse; /** * @since 0.1.0 * @category Combinators */ exports.orElseFirst = /*#__PURE__*/ ET.orElseFirst(S.Monad); /** * @since 0.1.0 * @category Combinators */ exports.orElseFirstW = exports.orElseFirst; /** * @since 0.1.0 * @category Combinators */ exports.orLeft = /*#__PURE__*/ ET.orLeft(S.Monad); /** * @since 0.1.0 * @category Combinators */ exports.swap = ET.swap(S.Functor); // ------------------------------------------------------------------------------------- // non-pipeables // ------------------------------------------------------------------------------------- /* istanbul ignore next */ var _map = function (fa, f) { return (0, function_1.pipe)(fa, (0, exports.map)(f)); }; /* istanbul ignore next */ var _ap = function (fab, fa) { return (0, function_1.pipe)(fab, (0, exports.ap)(fa)); }; /* istanbul ignore next */ var _chain = function (ma, f) { return (0, function_1.pipe)(ma, (0, exports.chain)(f)); }; /* istanbul ignore next */ var _biMap = function (fea, f, g) { return (0, function_1.pipe)(fea, (0, exports.bimap)(f, g)); }; /* istanbul ignore next */ var _mapLeft = function (fea, f) { return (0, function_1.pipe)(fea, (0, exports.mapLeft)(f)); }; /* istanbul ignore next */ var _alt = function (fx, fy) { return (0, function_1.pipe)(fx, (0, exports.alt)(fy)); }; // ------------------------------------------------------------------------------------- // type class members // ------------------------------------------------------------------------------------- /** * `map` can be used to turn functions `(a: A) => B` into functions `(fa: F<A>) * => F<B>` whose argument and return types use the type constructor `F` to * represent some computational context. * * @since 0.1.0 * @category Functor */ exports.map = ET.map(S.Functor); /** * Apply a function to an argument under a type constructoS. * * @since 0.6.0 * @category Apply */ exports.ap = ET.ap(S.Apply); /** * Combine two effectful actions, keeping only the result of the first. * * Derivable from `Apply`. * * @since 0.1.0 * @category Combinators */ var apFirst = function (fb) { return (0, function_1.flow)((0, exports.map)(function (a) { return function () { return a; }; }), (0, exports.ap)(fb)); }; exports.apFirst = apFirst; /** * Combine two effectful actions, keeping only the result of the second. * * Derivable from `Apply`. * * @since 0.1.0 * @category Combinators */ var apSecond = function (fb) { return (0, function_1.flow)((0, exports.map)(function () { return function (b) { return b; }; }), (0, exports.ap)(fb)); }; exports.apSecond = apSecond; /** * Identifies an associative operation on a type constructoS. It is similar to * `Semigroup`, except that it applies to types of kind `* -> *`. * * @since 0.1.0 * @category Alt */ exports.alt = ET.alt(S.Monad); /** * @since 0.1.0 * @category Bifunctor */ exports.bimap = ET.bimap(S.Functor); /** * @since 0.1.0 * @category Bifunctor */ exports.mapLeft = ET.mapLeft(S.Functor); /** * Less strict version of [`chain`](#chain). * * @since 0.1.0 * @category Monad */ var chainW = function (f) { return function (ma) { return (0, function_1.pipe)(ma, S.chain(E.fold(function (a) { return (0, exports.left)(a); }, f))); }; }; exports.chainW = chainW; /** * @since 0.1.0 * @category Monad */ exports.chain = exports.chainW; /** * Derivable from `Monad`. * * @since 0.6.0 * @category Combinators */ exports.flatten = /*#__PURE__*/ (0, exports.chain)(function_1.identity); /** @since 0.1.0 */ exports.of = exports.right; /** * Derivable from `MonadThrow`. * * @since 0.1.0 */ var filterOrElse = function (predicate, onFalse) { return (0, exports.chain)(function (a) { return (predicate(a) ? (0, exports.of)(a) : (0, exports.throwError)(onFalse(a))); }); }; exports.filterOrElse = filterOrElse; /** * Derivable from `MonadThrow`. * * @since 0.1.0 */ var fromEither = function (ma) { return (ma._tag === 'Left' ? (0, exports.throwError)(ma.left) : (0, exports.of)(ma.right)); }; exports.fromEither = fromEither; /** * Derivable from `MonadThrow`. * * @since 0.1.0 */ var fromOption = function (onNone) { return function (ma) { return ma._tag === 'None' ? (0, exports.throwError)(onNone()) : (0, exports.of)(ma.value); }; }; exports.fromOption = fromOption; /** * Derivable from `MonadThrow`. * * @since 0.1.0 */ var fromPredicate = function (predicate, onFalse) { return function (a) { return predicate(a) ? (0, exports.of)(a) : (0, exports.throwError)(onFalse(a)); }; }; exports.fromPredicate = fromPredicate; /** * @since 0.1.0 * @category MonadThrow */ exports.throwError = exports.left; // ------------------------------------------------------------------------------------- // instances // ------------------------------------------------------------------------------------- /** @since 2.0.0 */ exports.URI = 'wonka/SourceEither'; /** * @since 0.1.0 * @category Instances */ exports.Functor = { URI: exports.URI, map: _map, }; /** * Derivable from `Functor`. * * @since 0.1.0 * @category Combinators */ exports.flap = /*#__PURE__*/ (0, Functor_1.flap)(exports.Functor); /** * @since 0.1.0 * @category Instances */ exports.Pointed = { URI: exports.URI, of: exports.of, }; /** * @since 0.1.0 * @category Instances */ exports.Apply = { URI: exports.URI, map: _map, ap: _ap, }; /** * @since 0.1.0 * @category Instances */ exports.Applicative = { URI: exports.URI, map: _map, ap: _ap, of: exports.of, }; /** * @since 0.1.0 * @category Instances */ exports.Chain = { URI: exports.URI, map: _map, ap: _ap, chain: _chain, }; /** * Composes computations in sequence, using the return value of one computation * to determine the next computation and keeping only the result of the first. * * Derivable from `Monad`. * * @since 0.1.0 * @category Combinators */ exports.chainFirst = /*#__PURE__*/ (0, Chain_1.chainFirst)(exports.Chain); /** * Less strict version of [`chainFirst`](#chainfirst). * * Derivable from `Chain`. * * @since 0.1.0 * @category Combinators */ exports.chainFirstW = exports.chainFirst; /** * @since 0.1.0 * @category Instances */ exports.Monad = { URI: exports.URI, map: _map, ap: _ap, of: exports.of, chain: _chain, }; /** * @since 0.1.0 * @category Instances */ exports.Bifunctor = { URI: exports.URI, bimap: _biMap, mapLeft: _mapLeft, }; /** * @since 0.1.0 * @category Instances */ exports.Alt = { URI: exports.URI, map: _map, alt: _alt, }; /** * @since 0.1.0 * @category Instances */ exports.MonadIO = { URI: exports.URI, map: _map, ap: _ap, of: exports.of, chain: _chain, fromIO: exports.fromIO, }; /** * @since 0.1.0 * @category Instances */ exports.MonadTask = { URI: exports.URI, map: _map, ap: _ap, of: exports.of, chain: _chain, fromIO: exports.fromIO, fromTask: exports.fromTask, }; /** * @since 0.1.0 * @category Instances */ exports.MonadSource = { URI: exports.URI, map: _map, ap: _ap, of: exports.of, chain: _chain, fromIO: exports.fromIO, fromTask: exports.fromTask, fromSource: exports.fromSource, }; /** * @since 0.1.0 * @category Instances */ exports.MonadThrow = { URI: exports.URI, map: _map, ap: _ap, of: exports.of, chain: _chain, throwError: exports.throwError, }; // ------------------------------------------------------------------------------------- // do notation // ------------------------------------------------------------------------------------- /** @since 0.1.0 */ exports.Do = /*#__PURE__*/ (0, exports.of)({}); /** @since 0.1.0 */ exports.bindTo = /*#__PURE__*/ (0, Functor_1.bindTo)(exports.Functor); /** @since 0.1.0 */ exports.bind = /*#__PURE__*/ (0, Chain_1.bind)(exports.Chain); /** @since 0.1.0 */ exports.bindW = exports.bind; // ------------------------------------------------------------------------------------- // pipeable sequence S // ------------------------------------------------------------------------------------- /** @since 0.1.0 */ exports.apS = /*#__PURE__*/ (0, Apply_1.apS)(exports.Apply); /** @since 0.1.0 */ exports.apSW = exports.apS; // ------------------------------------------------------------------------------------- // utils // ------------------------------------------------------------------------------------- /** @since 0.1.0 */ exports.toTaskEither = S.toTask; //# sourceMappingURL=SourceEither.js.map