@matechs/effect
Advanced tools
Comparing version 0.0.22 to 0.0.23
@@ -5,3 +5,3 @@ import * as Ei from "fp-ts/lib/Either"; | ||
import * as EX from "waveguide/lib/exit"; | ||
import { Monad3E, MonadThrow3E } from "./overload"; | ||
import { Monad3E, MonadThrow3E, Monad3EC, MonadThrow3EC, Alt3EC } from "./overload"; | ||
import { Bifunctor3 } from "fp-ts/lib/Bifunctor"; | ||
@@ -14,2 +14,3 @@ import { Kind3, URIS3 } from "fp-ts/lib/HKT"; | ||
import { Exit } from "waveguide/lib/exit"; | ||
import { Semigroup } from "fp-ts/lib/Semigroup"; | ||
export { done, abort, raise, ExitTag, Exit, Cause, Abort, Done, Interrupt, interrupt, Raise } from "waveguide/lib/exit"; | ||
@@ -62,2 +63,5 @@ export { isDone, isAbort, isRaise, isInterrupt, fold, exit } from "./exit"; | ||
export declare const concurrentEffectMonad: MonadEffect<URI>; | ||
export declare function getCauseSemigroup<E>(S: Semigroup<E>): Semigroup<EX.Cause<E>>; | ||
export declare function getValidationM<E>(S: Semigroup<E>): Monad3EC<"matechs/Effect", E> & MonadThrow3EC<"matechs/Effect", E> & Alt3EC<"matechs/Effect", E>; | ||
export declare function getCauseValidationM<E>(S: Semigroup<Cause<E>>): Monad3EC<URI, E> & MonadThrow3EC<URI, E> & Alt3EC<URI, E>; | ||
export declare const ap: <R, E, A, R2, E2>(fa: Effect<R, E, A>) => <B>(fab: Effect<R2, E2, (a: A) => B>) => Effect<R & R2, E | E2, B>, apFirst: <R, E, B>(fb: Effect<R, E, B>) => <A, R2, E2>(fa: Effect<R2, E2, A>) => Effect<R & R2, E | E2, A>, apSecond: <R, E, B>(fb: Effect<R, E, B>) => <A, R2, E2>(fa: Effect<R2, E2, A>) => Effect<R & R2, E | E2, B>, chain: <R, E, A, B>(f: (a: A) => Effect<R, E, B>) => <R2, E2>(ma: Effect<R2, E2, A>) => Effect<R & R2, E | E2, B>, chainFirst: <R, E, A, B>(f: (a: A) => Effect<R, E, B>) => <R2, E2>(ma: Effect<R2, E2, A>) => Effect<R & R2, E | E2, A>, flatten: <R, E, R2, E2, A>(mma: Effect<R, E, Effect<R2, E2, A>>) => Effect<R & R2, E | E2, A>, map: <A, B>(f: (a: A) => B) => <R, E>(fa: Effect<R, E, A>) => Effect<R, E, B>, bimap: <E, G, A, B>(f: (e: E) => G, g: (a: A) => B) => <R>(fa: Effect<R, E, A>) => Effect<R, G, B>, filterOrElse: { | ||
@@ -64,0 +68,0 @@ <E, A, B extends A>(refinement: import("fp-ts/lib/function").Refinement<A, B>, onFalse: (a: A) => E): <R>(ma: Effect<R, E, A>) => Effect<R, E, B>; |
@@ -28,2 +28,3 @@ "use strict"; | ||
var S = __importStar(require("waveguide/lib/semaphore")); | ||
var EX = __importStar(require("waveguide/lib/exit")); | ||
var pipeable_1 = require("fp-ts/lib/pipeable"); | ||
@@ -172,2 +173,42 @@ var Option_1 = require("fp-ts/lib/Option"); | ||
exports.concurrentEffectMonad = __assign(__assign({}, exports.effectMonad), { ap: function (fab, fa) { return function (r) { return W.parWave.ap(fab(r), fa(r)); }; } }); | ||
function getCauseSemigroup(S) { | ||
return { | ||
concat: function (ca, cb) { | ||
if (ca._tag === EX.ExitTag.Interrupt || | ||
cb._tag === EX.ExitTag.Interrupt) { | ||
return ca; | ||
} | ||
if (ca._tag === EX.ExitTag.Abort) { | ||
return ca; | ||
} | ||
if (cb._tag === EX.ExitTag.Abort) { | ||
return cb; | ||
} | ||
return EX.raise(S.concat(ca.error, cb.error)); | ||
} | ||
}; | ||
} | ||
exports.getCauseSemigroup = getCauseSemigroup; | ||
function getValidationM(S) { | ||
return getCauseValidationM(getCauseSemigroup(S)); | ||
} | ||
exports.getValidationM = getValidationM; | ||
function getCauseValidationM(S) { | ||
return { | ||
URI: exports.URI, | ||
of: exports.effectMonad.of, | ||
map: exports.effectMonad.map, | ||
chain: exports.effectMonad.chain, | ||
ap: function (fab, fa) { return function (r) { | ||
return W.foldExit(fab(r), function (fabe) { | ||
return W.foldExit(fa(r), function (fae) { return W.raised(S.concat(fabe, fae)); }, function (_) { return W.raised(fabe); }); | ||
}, function (f) { return W.map(fa(r), f); }); | ||
}; }, | ||
throwError: function (e) { return function (_) { return W.raiseError(e); }; }, | ||
alt: function (fa, fb) { return function (r) { | ||
return W.foldExit(fa(r), function (e) { return W.foldExit(fb()(r), function (fbe) { return W.raised(S.concat(e, fbe)); }, W.pure); }, W.pure); | ||
}; } | ||
}; | ||
} | ||
exports.getCauseValidationM = getCauseValidationM; | ||
exports.ap = (_a = pipeable_1.pipeable(exports.effectMonad), _a.ap), exports.apFirst = _a.apFirst, exports.apSecond = _a.apSecond, exports.chain = _a.chain, exports.chainFirst = _a.chainFirst, exports.flatten = _a.flatten, exports.map = _a.map, exports.bimap = _a.bimap, exports.filterOrElse = _a.filterOrElse, exports.fromEither = _a.fromEither, exports.fromOption = _a.fromOption, exports.fromPredicate = _a.fromPredicate, exports.mapLeft = _a.mapLeft; | ||
@@ -174,0 +215,0 @@ exports.parAp = (_b = pipeable_1.pipeable(exports.concurrentEffectMonad), _b.ap), exports.parApFirst = _b.apFirst, exports.parApSecond = _b.apSecond; |
@@ -25,2 +25,17 @@ import "fp-ts-contrib/lib/Do"; | ||
} | ||
export interface Monad3EC<M extends URIS3, E> extends Applicative3EC<M, E>, Chain3EC<M, E> { | ||
} | ||
export interface Applicative3EC<F extends URIS3, E> extends Apply3EC<F, E> { | ||
readonly of: <R, A>(a: A) => Kind3<F, R, E, A>; | ||
} | ||
export interface Apply3EC<F extends URIS3, E> extends Functor3EC<F, E> { | ||
readonly ap: <R, A, B>(fab: Kind3<F, R, E, (a: A) => B>, fa: Kind3<F, R, E, A>) => Kind3<F, R, E, B>; | ||
} | ||
export interface Chain3EC<F extends URIS3, E> extends Apply3EC<F, E> { | ||
readonly chain: <R, A, R2, B>(fa: Kind3<F, R, E, A>, f: (a: A) => Kind3<F, R2, E, B>) => Kind3<F, R & R2, E, B>; | ||
} | ||
export interface Functor3EC<F extends URIS3, E> { | ||
readonly URI: F; | ||
readonly map: <R, A, B>(fa: Kind3<F, R, E, A>, f: (a: A) => B) => Kind3<F, R, E, B>; | ||
} | ||
declare type EnforceNonEmptyRecord<R> = keyof R extends never ? never : R; | ||
@@ -73,2 +88,8 @@ export interface Do3CE<M extends URIS3, S extends object, U, L> { | ||
} | ||
export interface MonadThrow3EC<M extends URIS3, E> extends Monad3EC<M, E> { | ||
readonly throwError: <R, A>(e: E) => Kind3<M, R, E, A>; | ||
} | ||
export interface Alt3EC<F extends URIS3, E> extends Functor3EC<F, E> { | ||
readonly alt: <R, A>(fx: Kind3<F, R, E, A>, fy: () => Kind3<F, R, E, A>) => Kind3<F, R, E, A>; | ||
} | ||
export {}; |
{ | ||
"name": "@matechs/effect", | ||
"version": "0.0.22", | ||
"version": "0.0.23", | ||
"license": "MIT", | ||
@@ -40,3 +40,3 @@ "private": false, | ||
}, | ||
"gitHead": "f25f40ed4d5c4d169cbf95e3f2099783dac495bd" | ||
"gitHead": "3ff547ce45a0fb1e20d3a8fe43e5cb42b1743fea" | ||
} |
Sorry, the diff of this file is not supported yet
198844
2976