UNPKG

@typed/fp

Version:

Data Structures and Resources for fp-ts

82 lines 2.77 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getOrElseW = exports.getOrElse = exports.matchEW = exports.matchE = exports.match3W = exports.matchW = exports.match = exports.alt = exports.chain = exports.ap = exports.map = exports.repleteF = exports.replete = exports.refresh = exports.fromProgress = exports.loading = exports.noData = void 0; const tslib_1 = require("tslib"); /** * DataT is a collection of transformers than can lift your effect types * to use Data to represent asynchronous loading. * @since 0.9.2 */ const Apply = (0, tslib_1.__importStar)(require("fp-ts/Apply")); const function_1 = require("fp-ts/function"); const Functor = (0, tslib_1.__importStar)(require("fp-ts/Functor")); const D = (0, tslib_1.__importStar)(require("./Data")); function noData(P) { return P.of(D.noData); } exports.noData = noData; function loading(P) { return P.of(D.loading); } exports.loading = loading; function fromProgress(P) { return (0, function_1.flow)(D.fromProgress, P.of); } exports.fromProgress = fromProgress; function refresh(P) { return (0, function_1.flow)(D.refresh, P.of); } exports.refresh = refresh; function replete(P) { return (0, function_1.flow)(D.replete, P.of); } exports.replete = replete; function repleteF(F) { return F.map(D.replete); } exports.repleteF = repleteF; function map(F) { return Functor.map(F, D.Functor); } exports.map = map; function ap(F) { return Apply.ap(F, D.Apply); } exports.ap = ap; function chain(M) { return (f) => (fa) => (0, function_1.pipe)(fa, M.chain((data) => (D.hasValue(data) ? f(data.value) : M.of(data)))); } exports.chain = chain; function alt(M) { return (second) => M.chain((e) => (D.hasValue(e) ? M.of(e) : second())); } exports.alt = alt; function match(F) { return (0, function_1.flow)(D.match, F.map); } exports.match = match; function matchW(F) { return (0, function_1.flow)(D.matchW, F.map); } exports.matchW = matchW; function match3W(F) { return (0, function_1.flow)(D.match3W, F.map); } exports.match3W = match3W; function matchE(C) { return (onNoData, onLoading, onRefresh, onReplete) => (data) => (0, function_1.pipe)(data, C.chain(D.matchW(onNoData, onLoading, onRefresh, onReplete))); } exports.matchE = matchE; function matchEW(C) { return (onNoData, onLoading, onRefresh, onReplete) => (data) => (0, function_1.pipe)(data, C.chain(D.matchW(onNoData, onLoading, onRefresh, onReplete))); } exports.matchEW = matchEW; function getOrElse(F) { return (0, function_1.flow)(D.getOrElse, F.map); } exports.getOrElse = getOrElse; function getOrElseW(F) { return (onData, onLoading) => F.map(D.getOrElseW(onData, onLoading)); } exports.getOrElseW = getOrElseW; //# sourceMappingURL=DataT.js.map