effect 3.10.7 → 3.10.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/Context.js +10 -0
- package/dist/cjs/Context.js.map +1 -1
- package/dist/cjs/Effect.js +32 -1
- package/dist/cjs/Effect.js.map +1 -1
- package/dist/cjs/Schema.js +42 -0
- package/dist/cjs/Schema.js.map +1 -1
- package/dist/cjs/TestClock.js +1 -1
- package/dist/cjs/TestClock.js.map +1 -1
- package/dist/cjs/internal/config.js +3 -3
- package/dist/cjs/internal/config.js.map +1 -1
- package/dist/cjs/internal/core-effect.js +3 -24
- package/dist/cjs/internal/core-effect.js.map +1 -1
- package/dist/cjs/internal/core.js +18 -4
- package/dist/cjs/internal/core.js.map +1 -1
- package/dist/cjs/internal/fiberRuntime.js +13 -6
- package/dist/cjs/internal/fiberRuntime.js.map +1 -1
- package/dist/cjs/internal/opCodes/effect.js +3 -1
- package/dist/cjs/internal/opCodes/effect.js.map +1 -1
- package/dist/cjs/internal/version.js +1 -1
- package/dist/dts/Context.d.ts +10 -0
- package/dist/dts/Context.d.ts.map +1 -1
- package/dist/dts/Effect.d.ts +37 -4
- package/dist/dts/Effect.d.ts.map +1 -1
- package/dist/dts/Schema.d.ts +116 -0
- package/dist/dts/Schema.d.ts.map +1 -1
- package/dist/dts/internal/core-effect.d.ts.map +1 -1
- package/dist/dts/internal/core.d.ts.map +1 -1
- package/dist/dts/internal/fiberRuntime.d.ts.map +1 -1
- package/dist/esm/Context.js +10 -0
- package/dist/esm/Context.js.map +1 -1
- package/dist/esm/Effect.js +32 -1
- package/dist/esm/Effect.js.map +1 -1
- package/dist/esm/Schema.js +42 -0
- package/dist/esm/Schema.js.map +1 -1
- package/dist/esm/TestClock.js +1 -1
- package/dist/esm/TestClock.js.map +1 -1
- package/dist/esm/internal/config.js +3 -3
- package/dist/esm/internal/config.js.map +1 -1
- package/dist/esm/internal/core-effect.js +0 -20
- package/dist/esm/internal/core-effect.js.map +1 -1
- package/dist/esm/internal/core.js +15 -2
- package/dist/esm/internal/core.js.map +1 -1
- package/dist/esm/internal/fiberRuntime.js +14 -7
- package/dist/esm/internal/fiberRuntime.js.map +1 -1
- package/dist/esm/internal/opCodes/effect.js +2 -0
- package/dist/esm/internal/opCodes/effect.js.map +1 -1
- package/dist/esm/internal/version.js +1 -1
- package/package.json +1 -1
- package/src/Context.ts +10 -0
- package/src/Effect.ts +41 -3
- package/src/Schema.ts +116 -0
- package/src/TestClock.ts +1 -1
- package/src/internal/config.ts +3 -3
- package/src/internal/core-effect.ts +0 -28
- package/src/internal/core.ts +25 -3
- package/src/internal/fiberRuntime.ts +19 -8
- package/src/internal/opCodes/effect.ts +6 -0
- package/src/internal/version.ts +1 -1
package/src/Effect.ts
CHANGED
|
@@ -1910,7 +1910,7 @@ export const gen: {
|
|
|
1910
1910
|
[Eff] extends [never] ? never : [Eff] extends [YieldWrap<Effect<infer _A, infer E, infer _R>>] ? E : never,
|
|
1911
1911
|
[Eff] extends [never] ? never : [Eff] extends [YieldWrap<Effect<infer _A, infer _E, infer R>>] ? R : never
|
|
1912
1912
|
>
|
|
1913
|
-
} =
|
|
1913
|
+
} = core.gen
|
|
1914
1914
|
|
|
1915
1915
|
/**
|
|
1916
1916
|
* @since 2.0.0
|
|
@@ -10732,6 +10732,8 @@ export declare namespace Tag {
|
|
|
10732
10732
|
: k
|
|
10733
10733
|
]: Type[k] extends (...args: infer Args extends ReadonlyArray<any>) => Effect<infer A, infer E, infer R> ?
|
|
10734
10734
|
(...args: Readonly<Args>) => Effect<A, E, Self | R>
|
|
10735
|
+
: Type[k] extends (...args: infer Args extends ReadonlyArray<any>) => Promise<infer A> ?
|
|
10736
|
+
(...args: Readonly<Args>) => Effect<A, Cause.UnknownException, Self>
|
|
10735
10737
|
: Type[k] extends (...args: infer Args extends ReadonlyArray<any>) => infer A ?
|
|
10736
10738
|
(...args: Readonly<Args>) => Effect<A, never, Self>
|
|
10737
10739
|
: Type[k] extends Effect<infer A, infer E, infer R> ? Effect<A, E, Self | R>
|
|
@@ -10768,6 +10770,16 @@ const makeTagProxy = (TagClass: Context.Tag<any, any> & Record<PropertyKey, any>
|
|
|
10768
10770
|
}
|
|
10769
10771
|
|
|
10770
10772
|
/**
|
|
10773
|
+
* @example
|
|
10774
|
+
* import { Effect, Layer } from "effect"
|
|
10775
|
+
*
|
|
10776
|
+
* class MapTag extends Effect.Tag("MapTag")<MapTag, Map<string, string>>() {
|
|
10777
|
+
* static Live = Layer.effect(
|
|
10778
|
+
* this,
|
|
10779
|
+
* Effect.sync(() => new Map())
|
|
10780
|
+
* )
|
|
10781
|
+
* }
|
|
10782
|
+
*
|
|
10771
10783
|
* @since 2.0.0
|
|
10772
10784
|
* @category context
|
|
10773
10785
|
*/
|
|
@@ -10780,7 +10792,9 @@ export const Tag: <const Id extends string>(id: Id) => <
|
|
|
10780
10792
|
& {
|
|
10781
10793
|
use: <X>(
|
|
10782
10794
|
body: (_: Type) => X
|
|
10783
|
-
) => X extends Effect<infer A, infer E, infer R> ? Effect<A, E, R | Self>
|
|
10795
|
+
) => [X] extends [Effect<infer A, infer E, infer R>] ? Effect<A, E, R | Self>
|
|
10796
|
+
: [X] extends [PromiseLike<infer A>] ? Effect<A, Cause.UnknownException, Self>
|
|
10797
|
+
: Effect<X, never, Self>
|
|
10784
10798
|
} = (id) => () => {
|
|
10785
10799
|
const limit = Error.stackTraceLimit
|
|
10786
10800
|
Error.stackTraceLimit = 2
|
|
@@ -10803,6 +10817,27 @@ export const Tag: <const Id extends string>(id: Id) => <
|
|
|
10803
10817
|
}
|
|
10804
10818
|
|
|
10805
10819
|
/**
|
|
10820
|
+
* @example
|
|
10821
|
+
* import { Effect } from 'effect';
|
|
10822
|
+
*
|
|
10823
|
+
* class Prefix extends Effect.Service<Prefix>()("Prefix", {
|
|
10824
|
+
* sync: () => ({ prefix: "PRE" })
|
|
10825
|
+
* }) {}
|
|
10826
|
+
*
|
|
10827
|
+
* class Logger extends Effect.Service<Logger>()("Logger", {
|
|
10828
|
+
* accessors: true,
|
|
10829
|
+
* effect: Effect.gen(function* () {
|
|
10830
|
+
* const { prefix } = yield* Prefix
|
|
10831
|
+
* return {
|
|
10832
|
+
* info: (message: string) =>
|
|
10833
|
+
* Effect.sync(() => {
|
|
10834
|
+
* console.log(`[${prefix}][${message}]`)
|
|
10835
|
+
* })
|
|
10836
|
+
* }
|
|
10837
|
+
* }),
|
|
10838
|
+
* dependencies: [Prefix.Default]
|
|
10839
|
+
* }) {}
|
|
10840
|
+
*
|
|
10806
10841
|
* @since 3.9.0
|
|
10807
10842
|
* @category context
|
|
10808
10843
|
* @experimental might be up for breaking changes
|
|
@@ -11033,10 +11068,13 @@ export declare namespace Service {
|
|
|
11033
11068
|
}
|
|
11034
11069
|
readonly use: <X>(
|
|
11035
11070
|
body: (_: Self) => X
|
|
11036
|
-
) => X extends Effect<infer A, infer E, infer R> ? Effect<A, E, R | Self>
|
|
11071
|
+
) => [X] extends [Effect<infer A, infer E, infer R>] ? Effect<A, E, R | Self>
|
|
11072
|
+
: [X] extends [PromiseLike<infer A>] ? Effect<A, Cause.UnknownException, Self>
|
|
11073
|
+
: Effect<X, never, Self>
|
|
11037
11074
|
readonly make: (_: MakeService<Make>) => Self
|
|
11038
11075
|
}
|
|
11039
11076
|
& Context.Tag<Self, Self>
|
|
11077
|
+
& { key: Key }
|
|
11040
11078
|
& (MakeAccessors<Make> extends true ? Tag.Proxy<Self, MakeService<Make>> : {})
|
|
11041
11079
|
& (MakeDeps<Make> extends never ? {
|
|
11042
11080
|
readonly Default: Layer.Layer<Self, MakeError<Make>, MakeContext<Make>>
|
package/src/Schema.ts
CHANGED
|
@@ -8240,6 +8240,26 @@ export interface Class<Self, Fields extends Struct.Fields, I, R, C, Inherited, P
|
|
|
8240
8240
|
|
|
8241
8241
|
readonly identifier: string
|
|
8242
8242
|
|
|
8243
|
+
/**
|
|
8244
|
+
* @example
|
|
8245
|
+
* import { Schema } from "effect"
|
|
8246
|
+
*
|
|
8247
|
+
* class MyClass extends Schema.Class<MyClass>("MyClass")({
|
|
8248
|
+
* myField: Schema.String
|
|
8249
|
+
* }) {
|
|
8250
|
+
* myMethod() {
|
|
8251
|
+
* return this.myField + "my"
|
|
8252
|
+
* }
|
|
8253
|
+
* }
|
|
8254
|
+
*
|
|
8255
|
+
* class NextClass extends MyClass.extend<NextClass>("NextClass")({
|
|
8256
|
+
* nextField: Schema.Number
|
|
8257
|
+
* }) {
|
|
8258
|
+
* nextMethod() {
|
|
8259
|
+
* return this.myMethod() + this.myField + this.nextField
|
|
8260
|
+
* }
|
|
8261
|
+
* }
|
|
8262
|
+
*/
|
|
8243
8263
|
extend<Extended = never>(identifier: string): <newFields extends Struct.Fields>(
|
|
8244
8264
|
fields: newFields | HasFields<newFields>,
|
|
8245
8265
|
annotations?: Annotations.Schema<Extended>
|
|
@@ -8254,6 +8274,33 @@ export interface Class<Self, Fields extends Struct.Fields, I, R, C, Inherited, P
|
|
|
8254
8274
|
Proto
|
|
8255
8275
|
>
|
|
8256
8276
|
|
|
8277
|
+
/**
|
|
8278
|
+
* @example
|
|
8279
|
+
* import { Effect, Schema } from "effect"
|
|
8280
|
+
*
|
|
8281
|
+
* class MyClass extends Schema.Class<MyClass>("MyClass")({
|
|
8282
|
+
* myField: Schema.String
|
|
8283
|
+
* }) {
|
|
8284
|
+
* myMethod() {
|
|
8285
|
+
* return this.myField + "my"
|
|
8286
|
+
* }
|
|
8287
|
+
* }
|
|
8288
|
+
*
|
|
8289
|
+
* class NextClass extends MyClass.transformOrFail<NextClass>("NextClass")({
|
|
8290
|
+
* nextField: Schema.Number
|
|
8291
|
+
* }, {
|
|
8292
|
+
* decode: (i) =>
|
|
8293
|
+
* Effect.succeed({
|
|
8294
|
+
* myField: i.myField,
|
|
8295
|
+
* nextField: i.myField.length
|
|
8296
|
+
* }),
|
|
8297
|
+
* encode: (a) => Effect.succeed({ myField: a.myField })
|
|
8298
|
+
* }) {
|
|
8299
|
+
* nextMethod() {
|
|
8300
|
+
* return this.myMethod() + this.myField + this.nextField
|
|
8301
|
+
* }
|
|
8302
|
+
* }
|
|
8303
|
+
*/
|
|
8257
8304
|
transformOrFail<Transformed = never>(identifier: string): <
|
|
8258
8305
|
newFields extends Struct.Fields,
|
|
8259
8306
|
R2,
|
|
@@ -8284,6 +8331,33 @@ export interface Class<Self, Fields extends Struct.Fields, I, R, C, Inherited, P
|
|
|
8284
8331
|
Proto
|
|
8285
8332
|
>
|
|
8286
8333
|
|
|
8334
|
+
/**
|
|
8335
|
+
* @example
|
|
8336
|
+
* import { Effect, Schema } from "effect"
|
|
8337
|
+
*
|
|
8338
|
+
* class MyClass extends Schema.Class<MyClass>("MyClass")({
|
|
8339
|
+
* myField: Schema.String
|
|
8340
|
+
* }) {
|
|
8341
|
+
* myMethod() {
|
|
8342
|
+
* return this.myField + "my"
|
|
8343
|
+
* }
|
|
8344
|
+
* }
|
|
8345
|
+
*
|
|
8346
|
+
* class NextClass extends MyClass.transformOrFailFrom<NextClass>("NextClass")({
|
|
8347
|
+
* nextField: Schema.Number
|
|
8348
|
+
* }, {
|
|
8349
|
+
* decode: (i) =>
|
|
8350
|
+
* Effect.succeed({
|
|
8351
|
+
* myField: i.myField,
|
|
8352
|
+
* nextField: i.myField.length
|
|
8353
|
+
* }),
|
|
8354
|
+
* encode: (a) => Effect.succeed({ myField: a.myField })
|
|
8355
|
+
* }) {
|
|
8356
|
+
* nextMethod() {
|
|
8357
|
+
* return this.myMethod() + this.myField + this.nextField
|
|
8358
|
+
* }
|
|
8359
|
+
* }
|
|
8360
|
+
*/
|
|
8287
8361
|
transformOrFailFrom<Transformed = never>(identifier: string): <
|
|
8288
8362
|
newFields extends Struct.Fields,
|
|
8289
8363
|
R2,
|
|
@@ -8334,6 +8408,17 @@ const getFieldsFromFieldsOr = <Fields extends Struct.Fields>(fieldsOr: Fields |
|
|
|
8334
8408
|
isFields(fieldsOr) ? fieldsOr : getFields(fieldsOr)
|
|
8335
8409
|
|
|
8336
8410
|
/**
|
|
8411
|
+
* @example
|
|
8412
|
+
* import { Schema } from "effect"
|
|
8413
|
+
*
|
|
8414
|
+
* class MyClass extends Schema.Class<MyClass>("MyClass")({
|
|
8415
|
+
* someField: Schema.String
|
|
8416
|
+
* }) {
|
|
8417
|
+
* someMethod() {
|
|
8418
|
+
* return this.someField + "bar"
|
|
8419
|
+
* }
|
|
8420
|
+
* }
|
|
8421
|
+
*
|
|
8337
8422
|
* @category classes
|
|
8338
8423
|
* @since 3.10.0
|
|
8339
8424
|
*/
|
|
@@ -8383,6 +8468,13 @@ export interface TaggedClass<Self, Tag extends string, Fields extends Struct.Fie
|
|
|
8383
8468
|
}
|
|
8384
8469
|
|
|
8385
8470
|
/**
|
|
8471
|
+
* @example
|
|
8472
|
+
* import { Schema } from "effect"
|
|
8473
|
+
*
|
|
8474
|
+
* class MyClass extends Schema.TaggedClass<MyClass>("MyClass")("MyClass", {
|
|
8475
|
+
* a: Schema.String
|
|
8476
|
+
* }) {}
|
|
8477
|
+
*
|
|
8386
8478
|
* @category classes
|
|
8387
8479
|
* @since 3.10.0
|
|
8388
8480
|
*/
|
|
@@ -8429,6 +8521,21 @@ export interface TaggedErrorClass<Self, Tag extends string, Fields extends Struc
|
|
|
8429
8521
|
}
|
|
8430
8522
|
|
|
8431
8523
|
/**
|
|
8524
|
+
* @example
|
|
8525
|
+
* import { Schema } from "effect"
|
|
8526
|
+
*
|
|
8527
|
+
* class MyError extends Schema.TaggedError<MyError>("MyError")(
|
|
8528
|
+
* "MyError",
|
|
8529
|
+
* {
|
|
8530
|
+
* module: Schema.String,
|
|
8531
|
+
* method: Schema.String,
|
|
8532
|
+
* description: Schema.String
|
|
8533
|
+
* }
|
|
8534
|
+
* ) {
|
|
8535
|
+
* get message(): string {
|
|
8536
|
+
* return `${this.module}.${this.method}: ${this.description}`
|
|
8537
|
+
* }
|
|
8538
|
+
* }
|
|
8432
8539
|
* @category classes
|
|
8433
8540
|
* @since 3.10.0
|
|
8434
8541
|
*/
|
|
@@ -10153,6 +10260,15 @@ export interface TaggedRequestClass<
|
|
|
10153
10260
|
}
|
|
10154
10261
|
|
|
10155
10262
|
/**
|
|
10263
|
+
* @example
|
|
10264
|
+
* import { Schema } from "effect"
|
|
10265
|
+
*
|
|
10266
|
+
* class MyRequest extends Schema.TaggedRequest<MyRequest>("MyRequest")("MyRequest", {
|
|
10267
|
+
* failure: Schema.String,
|
|
10268
|
+
* success: Schema.Number,
|
|
10269
|
+
* payload: { id: Schema.String }
|
|
10270
|
+
* }) {}
|
|
10271
|
+
*
|
|
10156
10272
|
* @category classes
|
|
10157
10273
|
* @since 3.10.0
|
|
10158
10274
|
*/
|
package/src/TestClock.ts
CHANGED
|
@@ -436,7 +436,7 @@ export class TestClockImpl implements TestClock {
|
|
|
436
436
|
export const live = (data: Data): Layer.Layer<TestClock, never, Annotations.TestAnnotations | Live.TestLive> =>
|
|
437
437
|
layer.scoped(
|
|
438
438
|
TestClock,
|
|
439
|
-
|
|
439
|
+
core.gen(function*($) {
|
|
440
440
|
const live = yield* $(Live.TestLive)
|
|
441
441
|
const annotations = yield* $(Annotations.TestAnnotations)
|
|
442
442
|
const clockState = yield* $(core.sync(() => ref.unsafeMake(data)))
|
package/src/internal/config.ts
CHANGED
|
@@ -223,7 +223,7 @@ export const number = (name?: string): Config.Config<number> => {
|
|
|
223
223
|
const config = primitive(
|
|
224
224
|
"a number property",
|
|
225
225
|
(text) => {
|
|
226
|
-
const result = Number
|
|
226
|
+
const result = Number(text)
|
|
227
227
|
if (Number.isNaN(result)) {
|
|
228
228
|
return Either.left(
|
|
229
229
|
configError.InvalidData(
|
|
@@ -243,8 +243,8 @@ export const integer = (name?: string): Config.Config<number> => {
|
|
|
243
243
|
const config = primitive(
|
|
244
244
|
"an integer property",
|
|
245
245
|
(text) => {
|
|
246
|
-
const result = Number
|
|
247
|
-
if (Number.
|
|
246
|
+
const result = Number(text)
|
|
247
|
+
if (!Number.isInteger(result)) {
|
|
248
248
|
return Either.left(
|
|
249
249
|
configError.InvalidData(
|
|
250
250
|
[],
|
|
@@ -29,7 +29,6 @@ import type * as runtimeFlagsPatch from "../RuntimeFlagsPatch.js"
|
|
|
29
29
|
import * as Tracer from "../Tracer.js"
|
|
30
30
|
import type { NoInfer } from "../Types.js"
|
|
31
31
|
import type { Unify } from "../Unify.js"
|
|
32
|
-
import { yieldWrapGet } from "../Utils.js"
|
|
33
32
|
import * as internalCause from "./cause.js"
|
|
34
33
|
import { clockTag } from "./clock.js"
|
|
35
34
|
import * as core from "./core.js"
|
|
@@ -794,33 +793,6 @@ export const forever = <A, E, R>(self: Effect.Effect<A, E, R>): Effect.Effect<ne
|
|
|
794
793
|
return loop
|
|
795
794
|
}
|
|
796
795
|
|
|
797
|
-
/**
|
|
798
|
-
* Inspired by https://github.com/tusharmath/qio/pull/22 (revised)
|
|
799
|
-
@internal */
|
|
800
|
-
export const gen: typeof Effect.gen = function() {
|
|
801
|
-
let f: any
|
|
802
|
-
if (arguments.length === 1) {
|
|
803
|
-
f = arguments[0]
|
|
804
|
-
} else {
|
|
805
|
-
f = arguments[1].bind(arguments[0])
|
|
806
|
-
}
|
|
807
|
-
return core.suspend(() => {
|
|
808
|
-
const iterator = f(pipe)
|
|
809
|
-
const state = internalCall(() => iterator.next())
|
|
810
|
-
const run = (
|
|
811
|
-
state: IteratorYieldResult<any> | IteratorReturnResult<any>
|
|
812
|
-
): Effect.Effect<any, any, any> => {
|
|
813
|
-
return (state.done
|
|
814
|
-
? core.succeed(state.value)
|
|
815
|
-
: core.flatMap(
|
|
816
|
-
yieldWrapGet(state.value) as any,
|
|
817
|
-
(val: any) => run(internalCall(() => iterator.next(val)))
|
|
818
|
-
))
|
|
819
|
-
}
|
|
820
|
-
return run(state)
|
|
821
|
-
})
|
|
822
|
-
}
|
|
823
|
-
|
|
824
796
|
/* @internal */
|
|
825
797
|
export const fiberRefs: Effect.Effect<FiberRefs.FiberRefs> = core.withFiberRuntime((state) =>
|
|
826
798
|
core.succeed(state.getFiberRefs())
|
package/src/internal/core.ts
CHANGED
|
@@ -122,6 +122,7 @@ export type Primitive =
|
|
|
122
122
|
| Sync
|
|
123
123
|
| UpdateRuntimeFlags
|
|
124
124
|
| While
|
|
125
|
+
| FromIterator
|
|
125
126
|
| WithRuntime
|
|
126
127
|
| Yield
|
|
127
128
|
| OpTag
|
|
@@ -137,6 +138,7 @@ export type Continuation =
|
|
|
137
138
|
| OnSuccessAndFailure
|
|
138
139
|
| OnFailure
|
|
139
140
|
| While
|
|
141
|
+
| FromIterator
|
|
140
142
|
| RevertFlags
|
|
141
143
|
|
|
142
144
|
/** @internal */
|
|
@@ -387,6 +389,13 @@ export interface While extends
|
|
|
387
389
|
}>
|
|
388
390
|
{}
|
|
389
391
|
|
|
392
|
+
/** @internal */
|
|
393
|
+
export interface FromIterator extends
|
|
394
|
+
Op<OpCodes.OP_ITERATOR, {
|
|
395
|
+
effect_instruction_i0: Iterator<YieldWrap<Primitive>, any>
|
|
396
|
+
}>
|
|
397
|
+
{}
|
|
398
|
+
|
|
390
399
|
/** @internal */
|
|
391
400
|
export interface WithRuntime extends
|
|
392
401
|
Op<OpCodes.OP_WITH_RUNTIME, {
|
|
@@ -435,7 +444,7 @@ export const acquireUseRelease: {
|
|
|
435
444
|
onFailure: (cause) => {
|
|
436
445
|
switch (exit._tag) {
|
|
437
446
|
case OpCodes.OP_FAILURE:
|
|
438
|
-
return failCause(internalCause.
|
|
447
|
+
return failCause(internalCause.sequential(exit.effect_instruction_i0, cause))
|
|
439
448
|
case OpCodes.OP_SUCCESS:
|
|
440
449
|
return failCause(cause)
|
|
441
450
|
}
|
|
@@ -1212,8 +1221,11 @@ export const succeed = <A>(value: A): Effect.Effect<A> => {
|
|
|
1212
1221
|
}
|
|
1213
1222
|
|
|
1214
1223
|
/* @internal */
|
|
1215
|
-
export const suspend = <A, E, R>(
|
|
1216
|
-
|
|
1224
|
+
export const suspend = <A, E, R>(evaluate: LazyArg<Effect.Effect<A, E, R>>): Effect.Effect<A, E, R> => {
|
|
1225
|
+
const effect = new EffectPrimitive(OpCodes.OP_COMMIT) as any
|
|
1226
|
+
effect.commit = evaluate
|
|
1227
|
+
return effect
|
|
1228
|
+
}
|
|
1217
1229
|
|
|
1218
1230
|
/* @internal */
|
|
1219
1231
|
export const sync = <A>(thunk: LazyArg<A>): Effect.Effect<A> => {
|
|
@@ -1404,6 +1416,16 @@ export const whileLoop = <A, E, R>(
|
|
|
1404
1416
|
return effect
|
|
1405
1417
|
}
|
|
1406
1418
|
|
|
1419
|
+
/* @internal */
|
|
1420
|
+
export const gen: typeof Effect.gen = function() {
|
|
1421
|
+
const f = arguments.length === 1 ? arguments[0] : arguments[1].bind(arguments[0])
|
|
1422
|
+
return suspend(() => {
|
|
1423
|
+
const effect = new EffectPrimitive(OpCodes.OP_ITERATOR) as any
|
|
1424
|
+
effect.effect_instruction_i0 = f(pipe)
|
|
1425
|
+
return effect
|
|
1426
|
+
})
|
|
1427
|
+
}
|
|
1428
|
+
|
|
1407
1429
|
/* @internal */
|
|
1408
1430
|
export const withConcurrency = dual<
|
|
1409
1431
|
(concurrency: number | "unbounded") => <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { internalCall } from "effect/Utils"
|
|
1
|
+
import { internalCall, yieldWrapGet } from "effect/Utils"
|
|
2
2
|
import * as RA from "../Array.js"
|
|
3
3
|
import * as Boolean from "../Boolean.js"
|
|
4
4
|
import type * as Cause from "../Cause.js"
|
|
@@ -189,6 +189,16 @@ const contOpSuccess = {
|
|
|
189
189
|
} else {
|
|
190
190
|
return core.void
|
|
191
191
|
}
|
|
192
|
+
},
|
|
193
|
+
[OpCodes.OP_ITERATOR]: (
|
|
194
|
+
self: FiberRuntime<any, any>,
|
|
195
|
+
cont: core.FromIterator,
|
|
196
|
+
value: unknown
|
|
197
|
+
) => {
|
|
198
|
+
const state = internalCall(() => cont.effect_instruction_i0.next(value))
|
|
199
|
+
if (state.done) return core.exitSucceed(state.value)
|
|
200
|
+
self.pushStack(cont)
|
|
201
|
+
return yieldWrapGet(state.value)
|
|
192
202
|
}
|
|
193
203
|
}
|
|
194
204
|
|
|
@@ -1053,7 +1063,7 @@ export class FiberRuntime<in out A, in out E = never> extends Effectable.Class<A
|
|
|
1053
1063
|
getNextFailCont() {
|
|
1054
1064
|
let frame = this.popStack()
|
|
1055
1065
|
while (frame) {
|
|
1056
|
-
if (frame._op !== OpCodes.OP_ON_SUCCESS && frame._op !== OpCodes.OP_WHILE) {
|
|
1066
|
+
if (frame._op !== OpCodes.OP_ON_SUCCESS && frame._op !== OpCodes.OP_WHILE && frame._op !== OpCodes.OP_ITERATOR) {
|
|
1057
1067
|
return frame
|
|
1058
1068
|
}
|
|
1059
1069
|
frame = this.popStack()
|
|
@@ -1299,6 +1309,10 @@ export class FiberRuntime<in out A, in out E = never> extends Effectable.Class<A
|
|
|
1299
1309
|
}
|
|
1300
1310
|
}
|
|
1301
1311
|
|
|
1312
|
+
[OpCodes.OP_ITERATOR](op: core.Primitive & { _op: OpCodes.OP_ITERATOR }) {
|
|
1313
|
+
return contOpSuccess[OpCodes.OP_ITERATOR](this, op, undefined)
|
|
1314
|
+
}
|
|
1315
|
+
|
|
1302
1316
|
[OpCodes.OP_COMMIT](op: core.Primitive & { _op: OpCodes.OP_COMMIT }) {
|
|
1303
1317
|
return internalCall(() => op.commit())
|
|
1304
1318
|
}
|
|
@@ -1330,11 +1344,6 @@ export class FiberRuntime<in out A, in out E = never> extends Effectable.Class<A
|
|
|
1330
1344
|
}
|
|
1331
1345
|
}
|
|
1332
1346
|
try {
|
|
1333
|
-
if (!("_op" in cur) || !((cur as core.Primitive)._op in this)) {
|
|
1334
|
-
// @ts-expect-error
|
|
1335
|
-
absurd(cur)
|
|
1336
|
-
}
|
|
1337
|
-
|
|
1338
1347
|
// @ts-expect-error
|
|
1339
1348
|
cur = this.currentTracer.context(
|
|
1340
1349
|
() => {
|
|
@@ -1369,7 +1378,9 @@ export class FiberRuntime<in out A, in out E = never> extends Effectable.Class<A
|
|
|
1369
1378
|
core.exitFailCause(internalCause.die(op))
|
|
1370
1379
|
}
|
|
1371
1380
|
} catch (e) {
|
|
1372
|
-
if (
|
|
1381
|
+
if (cur !== YieldedOp && !Predicate.hasProperty(cur, "_op") || !((cur as core.Primitive)._op in this)) {
|
|
1382
|
+
cur = core.dieMessage(`Not a valid effect: ${Inspectable.toStringUnknown(cur)}`)
|
|
1383
|
+
} else if (core.isEffectError(e)) {
|
|
1373
1384
|
cur = core.exitFailCause(e.cause)
|
|
1374
1385
|
} else if (core.isInterruptedException(e)) {
|
|
1375
1386
|
cur = core.exitFailCause(
|
|
@@ -64,6 +64,12 @@ export type OP_WHILE = typeof OP_WHILE
|
|
|
64
64
|
/** @internal */
|
|
65
65
|
export const OP_WHILE = "While" as const
|
|
66
66
|
|
|
67
|
+
/** @internal */
|
|
68
|
+
export type OP_ITERATOR = typeof OP_ITERATOR
|
|
69
|
+
|
|
70
|
+
/** @internal */
|
|
71
|
+
export const OP_ITERATOR = "Iterator" as const
|
|
72
|
+
|
|
67
73
|
/** @internal */
|
|
68
74
|
export type OP_WITH_RUNTIME = typeof OP_WITH_RUNTIME
|
|
69
75
|
|
package/src/internal/version.ts
CHANGED