fp-ts-bracket
Version:
Bracket monad for fp-ts
40 lines (39 loc) • 1.09 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.as = as;
exports.asUnit = asUnit;
exports.tap = tap;
exports.tapEither = tapEither;
exports.tapIO = tapIO;
exports.tapTask = tapTask;
const FromEither_1 = require("fp-ts/lib/FromEither");
const function_1 = require("fp-ts/lib/function");
/** @internal */
function as(F) {
return (self, b) => F.map(self, () => b);
}
/** @internal */
function asUnit(F) {
const asM = as(F);
return (self) => asM(self, undefined);
}
/** @internal */
function tap(M) {
return (first, f) => M.chain(first, (a) => M.map(f(a), () => a));
}
/** @internal */
function tapEither(F, M) {
const fromEither = (0, FromEither_1.fromEitherK)(F);
const tapM = tap(M);
return (self, f) => tapM(self, fromEither(f));
}
/** @internal */
function tapIO(F, M) {
const chainFirstM = tap(M);
return (self, f) => chainFirstM(self, (0, function_1.flow)(f, F.fromIO));
}
/** @internal */
function tapTask(F, M) {
const tapM = tap(M);
return (self, f) => tapM(self, (0, function_1.flow)(f, F.fromTask));
}