@matechs/effect
Advanced tools
Comparing version 0.2.6 to 0.2.7
@@ -7,3 +7,2 @@ import { Either } from "fp-ts/lib/Either"; | ||
import * as T from "./effect"; | ||
declare type UnkIO = T.Effect<unknown, unknown, unknown>; | ||
export declare type RegionFrameType = InterruptFrame; | ||
@@ -13,12 +12,12 @@ export declare type FrameType = Frame | FoldFrame | RegionFrameType; | ||
readonly _tag: "frame"; | ||
apply(u: unknown): UnkIO; | ||
apply(u: unknown): T.Instructions; | ||
} | ||
interface FoldFrame { | ||
readonly _tag: "fold-frame"; | ||
apply(u: unknown): UnkIO; | ||
recover(cause: Cause<unknown>): UnkIO; | ||
apply(u: unknown): T.Instructions; | ||
recover(cause: Cause<unknown>): T.Instructions; | ||
} | ||
declare class FoldFrame implements FoldFrame { | ||
private readonly c; | ||
constructor(c: T.EffectIOImpl); | ||
constructor(c: T.Collapse); | ||
readonly _tag: "fold-frame"; | ||
@@ -28,3 +27,3 @@ } | ||
readonly _tag: "interrupt-frame"; | ||
apply(u: unknown): UnkIO; | ||
apply(u: unknown): T.Instructions; | ||
exitRegion(): void; | ||
@@ -57,8 +56,8 @@ } | ||
isInterruptible(): boolean; | ||
handle(e: Cause<unknown>): UnkIO | undefined; | ||
handle(e: Cause<unknown>): T.Instructions | undefined; | ||
resumeInterrupt(): void; | ||
next(value: unknown): UnkIO | undefined; | ||
next(value: unknown): T.Instructions | undefined; | ||
resume(status: Either<unknown, unknown>): void; | ||
contextSwitch(op: FunctionN<[FunctionN<[Either<unknown, unknown>], void>], Lazy<void>>): void; | ||
loop(go: UnkIO): void; | ||
loop(go: T.Instructions): void; | ||
start(run: T.Effect<NoEnv, E, A>): void; | ||
@@ -65,0 +64,0 @@ interrupt(): void; |
@@ -38,3 +38,3 @@ "use strict"; | ||
interruptStatus.pop(); | ||
return T.pure(u); | ||
return T.EffectIO.fromEffect(T.pure(u)); | ||
}, | ||
@@ -195,3 +195,3 @@ exitRegion: function () { | ||
this.envStack.push(current.f1); | ||
current = T.effect.chainError(T.effect.chain(current.f0, function (r) { | ||
current = T.EffectIO.fromEffect(T.effect.chainError(T.effect.chain(current.f0, function (r) { | ||
return T.sync(function () { | ||
@@ -206,3 +206,3 @@ _this.envStack.pop(); | ||
}), function (_) { return T.raiseError(e); }); | ||
}); | ||
})); | ||
break; | ||
@@ -213,4 +213,3 @@ case T.EffectTag.Pure: | ||
case T.EffectTag.Raised: | ||
if (current.f0._tag === | ||
exit_1.ExitTag.Interrupt) { | ||
if (current.f0._tag === exit_1.ExitTag.Interrupt) { | ||
this.interrupted = true; | ||
@@ -221,8 +220,7 @@ } | ||
case T.EffectTag.Completed: | ||
var ex = current.f0; | ||
if (ex._tag === exit_1.ExitTag.Done) { | ||
current = this.next(ex.value); | ||
if (current.f0._tag === exit_1.ExitTag.Done) { | ||
current = this.next(current.f0.value); | ||
} | ||
else { | ||
current = this.handle(ex); | ||
current = this.handle(current.f0); | ||
} | ||
@@ -247,5 +245,3 @@ break; | ||
if (this.interruptRegionStack === undefined) { | ||
this.interruptRegionStack = [ | ||
current.f0 | ||
]; | ||
this.interruptRegionStack = [current.f0]; | ||
} | ||
@@ -259,6 +255,6 @@ else { | ||
case T.EffectTag.AccessRuntime: | ||
current = T.pure(current.f0(this.runtime)); | ||
current = T.EffectIO.fromEffect(T.pure(current.f0(this.runtime))); | ||
break; | ||
case T.EffectTag.AccessInterruptible: | ||
current = T.pure(current.f0(this.isInterruptible())); | ||
current = T.EffectIO.fromEffect(T.pure(current.f0(this.isInterruptible()))); | ||
break; | ||
@@ -270,3 +266,3 @@ default: | ||
catch (e) { | ||
current = T.raiseAbort(e); | ||
current = T.EffectIO.fromEffect(T.raiseAbort(e)); | ||
} | ||
@@ -285,3 +281,3 @@ } | ||
this.started = true; | ||
this.runtime.dispatch(function () { return _this.loop(run); }); | ||
this.runtime.dispatch(function () { return _this.loop(T.EffectIO.fromEffect(run)); }); | ||
}; | ||
@@ -288,0 +284,0 @@ DriverImpl.prototype.interrupt = function () { |
@@ -38,3 +38,3 @@ import { Bifunctor3 } from "fp-ts/lib/Bifunctor"; | ||
} | ||
export declare class EffectIOImpl { | ||
export declare class EffectIO<R, E, A> { | ||
readonly _tag: EffectTag; | ||
@@ -44,4 +44,61 @@ readonly f0: any; | ||
readonly f2: any; | ||
static fromEffect<R, E, A>(eff: Effect<R, E, A>): EffectIO<R, E, A>; | ||
constructor(_tag: EffectTag, f0?: any, f1?: any, f2?: any); | ||
asEffect: Effect<R, E, A>; | ||
asInstructions: Instructions; | ||
} | ||
export declare type Instructions = Pure | Raised | Completed | Suspended | Async | Chain | Collapse | InterruptibleRegion | AccessInterruptible | AccessRuntime | AccessEnv | ProvideEnv; | ||
export interface Pure<A = unknown> { | ||
readonly _tag: EffectTag.Pure; | ||
readonly f0: A; | ||
} | ||
export interface Raised<E = unknown> { | ||
readonly _tag: EffectTag.Raised; | ||
readonly f0: Cause<E>; | ||
} | ||
export interface Completed<E = unknown, A = unknown> { | ||
readonly _tag: EffectTag.Completed; | ||
readonly f0: Exit<E, A>; | ||
} | ||
export interface Suspended<E = unknown, A = unknown> { | ||
readonly _tag: EffectTag.Suspended; | ||
readonly f0: Lazy<EffectIO<NoEnv, E, A>>; | ||
} | ||
export interface Async<E = unknown, A = unknown> { | ||
readonly _tag: EffectTag.Async; | ||
readonly f0: FunctionN<[FunctionN<[Either<E, A>], void>], Lazy<void>>; | ||
} | ||
export interface Chain<Z = unknown> { | ||
readonly _tag: EffectTag.Chain; | ||
readonly f0: Instructions; | ||
readonly f1: FunctionN<[Z], Instructions>; | ||
} | ||
export interface Collapse<E1 = unknown, A1 = unknown> { | ||
readonly _tag: EffectTag.Collapse; | ||
readonly f0: Instructions; | ||
readonly f1: FunctionN<[Cause<E1>], Instructions>; | ||
readonly f2: FunctionN<[A1], Instructions>; | ||
} | ||
export interface InterruptibleRegion { | ||
readonly _tag: EffectTag.InterruptibleRegion; | ||
readonly f0: boolean; | ||
readonly f1: Instructions; | ||
} | ||
export interface AccessInterruptible<A = unknown> { | ||
readonly _tag: EffectTag.AccessInterruptible; | ||
readonly f0: FunctionN<[boolean], A>; | ||
} | ||
export interface AccessRuntime<A = unknown> { | ||
readonly _tag: EffectTag.AccessRuntime; | ||
readonly f0: FunctionN<[Runtime], A>; | ||
} | ||
export interface ProvideEnv<R = unknown> { | ||
readonly _tag: EffectTag.ProvideEnv; | ||
readonly f0: Instructions; | ||
readonly f1: R; | ||
} | ||
export interface AccessEnv<R = unknown> { | ||
readonly _tag: EffectTag.AccessEnv; | ||
readonly f0: R; | ||
} | ||
/** | ||
@@ -48,0 +105,0 @@ * An IO has succeeded |
@@ -56,4 +56,4 @@ "use strict"; | ||
exports.noEnv = {}; | ||
var EffectIOImpl = /** @class */ (function () { | ||
function EffectIOImpl(_tag, f0, f1, f2) { | ||
var EffectIO = /** @class */ (function () { | ||
function EffectIO(_tag, f0, f1, f2) { | ||
if (f0 === void 0) { f0 = exports.noEnv; } | ||
@@ -66,6 +66,11 @@ if (f1 === void 0) { f1 = exports.noEnv; } | ||
this.f2 = f2; | ||
this.asEffect = this; | ||
this.asInstructions = this; | ||
} | ||
return EffectIOImpl; | ||
EffectIO.fromEffect = function (eff) { | ||
return eff; | ||
}; | ||
return EffectIO; | ||
}()); | ||
exports.EffectIOImpl = EffectIOImpl; | ||
exports.EffectIO = EffectIO; | ||
/** | ||
@@ -76,3 +81,3 @@ * An IO has succeeded | ||
function pure(a) { | ||
return new EffectIOImpl(EffectTag.Pure, a); | ||
return new EffectIO(EffectTag.Pure, a).asEffect; | ||
} | ||
@@ -87,3 +92,3 @@ exports.pure = pure; | ||
function raised(e) { | ||
return new EffectIOImpl(EffectTag.Raised, e); | ||
return new EffectIO(EffectTag.Raised, e).asEffect; | ||
} | ||
@@ -116,3 +121,3 @@ exports.raised = raised; | ||
function completed(exit) { | ||
return new EffectIOImpl(EffectTag.Completed, exit); | ||
return new EffectIO(EffectTag.Completed, exit).asEffect; | ||
} | ||
@@ -127,3 +132,3 @@ exports.completed = completed; | ||
function suspended(thunk) { | ||
return new EffectIOImpl(EffectTag.Suspended, thunk); | ||
return new EffectIO(EffectTag.Suspended, thunk).asEffect; | ||
} | ||
@@ -174,3 +179,3 @@ exports.suspended = suspended; | ||
function async(op) { | ||
return new EffectIOImpl(EffectTag.Async, op); | ||
return new EffectIO(EffectTag.Async, op).asEffect; | ||
} | ||
@@ -194,3 +199,3 @@ exports.async = async; | ||
function interruptibleRegion(inner, flag) { | ||
return new EffectIOImpl(EffectTag.InterruptibleRegion, flag, inner); | ||
return new EffectIO(EffectTag.InterruptibleRegion, flag, inner).asEffect; | ||
} | ||
@@ -204,3 +209,3 @@ exports.interruptibleRegion = interruptibleRegion; | ||
function chain_(inner, bind) { | ||
return new EffectIOImpl(EffectTag.Chain, inner, bind); | ||
return new EffectIO(EffectTag.Chain, inner, bind).asEffect; | ||
} | ||
@@ -236,7 +241,7 @@ /** | ||
*/ | ||
exports.accessInterruptible = new EffectIOImpl(EffectTag.AccessInterruptible, function_1.identity); | ||
exports.accessInterruptible = new EffectIO(EffectTag.AccessInterruptible, function_1.identity).asEffect; | ||
/** | ||
* Get the runtime of the current fiber | ||
*/ | ||
exports.accessRuntime = new EffectIOImpl(EffectTag.AccessRuntime, function_1.identity); | ||
exports.accessRuntime = new EffectIO(EffectTag.AccessRuntime, function_1.identity).asEffect; | ||
/** | ||
@@ -251,3 +256,3 @@ * Access the runtime then provide it to the provided function | ||
function accessEnvironment() { | ||
return new EffectIOImpl(EffectTag.AccessEnv); | ||
return new EffectIO(EffectTag.AccessEnv).asEffect; | ||
} | ||
@@ -280,3 +285,3 @@ exports.accessEnvironment = accessEnvironment; | ||
*/ | ||
exports.provideAll = function (r) { return function (ma) { return new EffectIOImpl(EffectTag.ProvideEnv, ma, r); }; }; | ||
exports.provideAll = function (r) { return function (ma) { return new EffectIO(EffectTag.ProvideEnv, ma, r).asEffect; }; }; | ||
/** | ||
@@ -300,3 +305,3 @@ * Provides all environment necessary to the child effect via an effect | ||
function map_(base, f) { | ||
return new EffectIOImpl(EffectTag.Chain, base, function (x) { return new EffectIOImpl(EffectTag.Pure, f(x)); }); | ||
return new EffectIO(EffectTag.Chain, base, function (x) { return new EffectIO(EffectTag.Pure, f(x)); }).asEffect; | ||
} | ||
@@ -967,3 +972,3 @@ /** | ||
var foldExit_ = function (inner, failure, success) { | ||
return new EffectIOImpl(EffectTag.Collapse, inner, failure, success); | ||
return new EffectIO(EffectTag.Collapse, inner, failure, success).asEffect; | ||
}; | ||
@@ -970,0 +975,0 @@ var mapLeft_ = function (io, f) { |
{ | ||
"name": "@matechs/effect", | ||
"version": "0.2.6", | ||
"version": "0.2.7", | ||
"license": "MIT", | ||
@@ -23,2 +23,3 @@ "private": false, | ||
"@babel/preset-typescript": "^7.7.4", | ||
"@qio/core": "^27.1.0", | ||
"@types/benchmark": "^1.0.31", | ||
@@ -42,6 +43,3 @@ "@types/chai": "^4.2.5", | ||
}, | ||
"gitHead": "583e1f0410fb08c57f70a944cf092a2d8115386c", | ||
"dependencies": { | ||
"@qio/core": "^27.1.0" | ||
} | ||
"gitHead": "97986a7b8b23c02d5ab98706d20a183351e29b90" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
344194
2
6114
17
- Removed@qio/core@^27.1.0
- Removed@qio/core@27.1.0(transitive)
- Removed@qio/prelude@27.0.4(transitive)
- Removedchecked-exceptions@1.2.0(transitive)
- Removeddebug@4.4.0(transitive)
- Removedin-node@1.0.0(transitive)
- Removedms@2.1.3(transitive)
- Removedstandard-data-structures@4.0.0(transitive)
- Removedts-scheduler@8.0.4(transitive)