dashp
Version:
Utilities for monadic promises.
53 lines (46 loc) • 1.46 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.flow8 = exports.flow7 = exports.flow6 = exports.flow5 = exports.flow4 = exports.flow3 = exports.flow2 = exports.flow = exports.flowN = void 0;
var _Future = require("./Future");
var _curry = _interopRequireDefault(require("./internal/curry"));
var _identity = _interopRequireDefault(require("./internal/identity"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
const flowN = (fs, ...xs) => {
// If we encounter a call to `caught`, wrap the whole block in an exception
// handler.
const [head, ...tail] = fs.reduce((memo, f) => {
if (/^caught-/.test(f.name)) return [p => f(flowN(memo, p))];
return memo.concat(f);
}, []);
const f = head || _identity.default;
return tail.reduce((memo, g) => memo.then(g), (0, _Future.of)(f(...xs)));
};
exports.flowN = flowN;
const {
flow,
flow2,
flow3,
flow4,
flow5,
flow6,
flow7,
flow8
} = Array.from(...[Array(8).keys()]).reduce((memo, i) => {
const name = `flow${i === 0 ? "" : i + 1}`;
const curry = _curry.default[`curry${i + 2}`];
const g = curry(name, flowN);
return Object.assign(memo, {
[name]: g
});
}, {});
exports.flow8 = flow8;
exports.flow7 = flow7;
exports.flow6 = flow6;
exports.flow5 = flow5;
exports.flow4 = flow4;
exports.flow3 = flow3;
exports.flow2 = flow2;
exports.flow = flow;
//# sourceMappingURL=flow.js.map