@typed/fx 1.22.2 → 1.24.0
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/AsyncData.js.map +1 -1
- package/dist/cjs/Form.js.map +1 -1
- package/dist/cjs/FormEntry.js.map +1 -1
- package/dist/cjs/Fx.js +1 -1
- package/dist/cjs/Fx.js.map +1 -1
- package/dist/cjs/Idle.js.map +1 -1
- package/dist/cjs/Match.js.map +1 -1
- package/dist/cjs/Pull.js +5 -3
- package/dist/cjs/Pull.js.map +1 -1
- package/dist/cjs/RefArray.js.map +1 -1
- package/dist/cjs/RefChunk.js.map +1 -1
- package/dist/cjs/RefHashSet.js.map +1 -1
- package/dist/cjs/RefSubject.js +3 -2
- package/dist/cjs/RefSubject.js.map +1 -1
- package/dist/cjs/Sink.js.map +1 -1
- package/dist/cjs/Subject.js.map +1 -1
- package/dist/cjs/Versioned.js.map +1 -1
- package/dist/cjs/internal/core.js.map +1 -1
- package/dist/cjs/internal/helpers.js.map +1 -1
- package/dist/cjs/internal/keyed.js +1 -1
- package/dist/cjs/internal/keyed.js.map +1 -1
- package/dist/cjs/internal/provide.js.map +1 -1
- package/dist/cjs/internal/share.js.map +1 -1
- package/dist/cjs/internal/sync-producer.js.map +1 -1
- package/dist/dts/AsyncData.d.ts +53 -53
- package/dist/dts/AsyncData.d.ts.map +1 -1
- package/dist/dts/Emitter.d.ts +7 -7
- package/dist/dts/Emitter.d.ts.map +1 -1
- package/dist/dts/Form.d.ts +14 -14
- package/dist/dts/Form.d.ts.map +1 -1
- package/dist/dts/FormEntry.d.ts +11 -11
- package/dist/dts/FormEntry.d.ts.map +1 -1
- package/dist/dts/Fx.d.ts +417 -417
- package/dist/dts/Fx.d.ts.map +1 -1
- package/dist/dts/Guard.d.ts +21 -21
- package/dist/dts/Guard.d.ts.map +1 -1
- package/dist/dts/Idle.d.ts +12 -12
- package/dist/dts/Idle.d.ts.map +1 -1
- package/dist/dts/Match.d.ts +16 -16
- package/dist/dts/Match.d.ts.map +1 -1
- package/dist/dts/Pull.d.ts +5 -5
- package/dist/dts/Pull.d.ts.map +1 -1
- package/dist/dts/Push.d.ts +40 -40
- package/dist/dts/Push.d.ts.map +1 -1
- package/dist/dts/RefArray.d.ts +59 -59
- package/dist/dts/RefArray.d.ts.map +1 -1
- package/dist/dts/RefChunk.d.ts +45 -45
- package/dist/dts/RefChunk.d.ts.map +1 -1
- package/dist/dts/RefHashMap.d.ts +35 -35
- package/dist/dts/RefHashMap.d.ts.map +1 -1
- package/dist/dts/RefHashSet.d.ts +17 -17
- package/dist/dts/RefHashSet.d.ts.map +1 -1
- package/dist/dts/RefSubject.d.ts +136 -136
- package/dist/dts/RefSubject.d.ts.map +1 -1
- package/dist/dts/Sink.d.ts +63 -63
- package/dist/dts/Sink.d.ts.map +1 -1
- package/dist/dts/Stream.d.ts +11 -11
- package/dist/dts/Stream.d.ts.map +1 -1
- package/dist/dts/Subject.d.ts +13 -13
- package/dist/dts/Subject.d.ts.map +1 -1
- package/dist/dts/Typeclass.d.ts +1 -1
- package/dist/dts/Typeclass.d.ts.map +1 -1
- package/dist/dts/Versioned.d.ts +33 -33
- package/dist/dts/Versioned.d.ts.map +1 -1
- package/dist/dts/index.d.ts +1 -1
- package/dist/dts/internal/DeferredRef.d.ts +8 -8
- package/dist/dts/internal/DeferredRef.d.ts.map +1 -1
- package/dist/dts/internal/core.d.ts +191 -191
- package/dist/dts/internal/core.d.ts.map +1 -1
- package/dist/dts/internal/effect-loop-operator.d.ts +6 -6
- package/dist/dts/internal/effect-loop-operator.d.ts.map +1 -1
- package/dist/dts/internal/effect-operator.d.ts +16 -16
- package/dist/dts/internal/effect-operator.d.ts.map +1 -1
- package/dist/dts/internal/effect-producer.d.ts +13 -13
- package/dist/dts/internal/effect-producer.d.ts.map +1 -1
- package/dist/dts/internal/helpers.d.ts +26 -26
- package/dist/dts/internal/helpers.d.ts.map +1 -1
- package/dist/dts/internal/keyed.d.ts +1 -1
- package/dist/dts/internal/keyed.d.ts.map +1 -1
- package/dist/dts/internal/loop-operator.d.ts +2 -2
- package/dist/dts/internal/loop-operator.d.ts.map +1 -1
- package/dist/dts/internal/operator.d.ts +2 -2
- package/dist/dts/internal/operator.d.ts.map +1 -1
- package/dist/dts/internal/protos.d.ts +12 -12
- package/dist/dts/internal/protos.d.ts.map +1 -1
- package/dist/dts/internal/provide.d.ts +15 -15
- package/dist/dts/internal/provide.d.ts.map +1 -1
- package/dist/dts/internal/share.d.ts +11 -11
- package/dist/dts/internal/share.d.ts.map +1 -1
- package/dist/dts/internal/sync-operator.d.ts +2 -2
- package/dist/dts/internal/sync-operator.d.ts.map +1 -1
- package/dist/dts/internal/sync-producer.d.ts +6 -6
- package/dist/dts/internal/sync-producer.d.ts.map +1 -1
- package/dist/dts/internal/withKey.d.ts +1 -1
- package/dist/dts/internal/withKey.d.ts.map +1 -1
- package/dist/esm/AsyncData.js.map +1 -1
- package/dist/esm/Form.js.map +1 -1
- package/dist/esm/FormEntry.js.map +1 -1
- package/dist/esm/Fx.js +1 -1
- package/dist/esm/Fx.js.map +1 -1
- package/dist/esm/Idle.js.map +1 -1
- package/dist/esm/Match.js.map +1 -1
- package/dist/esm/Pull.js +3 -3
- package/dist/esm/Pull.js.map +1 -1
- package/dist/esm/RefArray.js.map +1 -1
- package/dist/esm/RefChunk.js.map +1 -1
- package/dist/esm/RefHashSet.js.map +1 -1
- package/dist/esm/RefSubject.js +3 -1
- package/dist/esm/RefSubject.js.map +1 -1
- package/dist/esm/Sink.js.map +1 -1
- package/dist/esm/Subject.js.map +1 -1
- package/dist/esm/Versioned.js.map +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/internal/core.js.map +1 -1
- package/dist/esm/internal/helpers.js.map +1 -1
- package/dist/esm/internal/keyed.js +1 -1
- package/dist/esm/internal/keyed.js.map +1 -1
- package/dist/esm/internal/provide.js.map +1 -1
- package/dist/esm/internal/share.js.map +1 -1
- package/dist/esm/internal/sync-producer.js.map +1 -1
- package/package.json +6 -6
- package/src/AsyncData.ts +142 -144
- package/src/Emitter.ts +13 -13
- package/src/Form.ts +55 -55
- package/src/FormEntry.ts +39 -39
- package/src/Fx.ts +788 -789
- package/src/Guard.ts +43 -43
- package/src/Idle.ts +26 -26
- package/src/Match.ts +60 -61
- package/src/Pull.ts +42 -43
- package/src/Push.ts +195 -195
- package/src/RefArray.ts +121 -119
- package/src/RefChunk.ts +98 -97
- package/src/RefHashMap.ts +79 -79
- package/src/RefHashSet.ts +40 -39
- package/src/RefSubject.ts +574 -565
- package/src/Sink.ts +303 -303
- package/src/Stream.ts +27 -27
- package/src/Subject.ts +48 -46
- package/src/Typeclass.ts +2 -2
- package/src/Versioned.ts +97 -97
- package/src/index.ts +1 -1
- package/src/internal/DeferredRef.ts +7 -7
- package/src/internal/core.ts +768 -781
- package/src/internal/effect-loop-operator.ts +7 -7
- package/src/internal/effect-operator.ts +23 -23
- package/src/internal/effect-producer.ts +38 -38
- package/src/internal/helpers.ts +51 -51
- package/src/internal/keyed.ts +21 -21
- package/src/internal/loop-operator.ts +2 -2
- package/src/internal/operator.ts +2 -2
- package/src/internal/protos.ts +15 -15
- package/src/internal/provide.ts +27 -27
- package/src/internal/share.ts +25 -25
- package/src/internal/sync-operator.ts +4 -4
- package/src/internal/sync-producer.ts +15 -15
- package/src/internal/withKey.ts +13 -13
package/src/Guard.ts
CHANGED
|
@@ -10,7 +10,7 @@ import * as Option from "effect/Option"
|
|
|
10
10
|
/**
|
|
11
11
|
* @since 1.18.0
|
|
12
12
|
*/
|
|
13
|
-
export type Guard<in I, out
|
|
13
|
+
export type Guard<in I, out O, out E = never, out R = never> = (input: I) => Effect.Effect<Option.Option<O>, E, R>
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
16
|
* @since 1.18.0
|
|
@@ -23,27 +23,27 @@ export namespace Guard {
|
|
|
23
23
|
/**
|
|
24
24
|
* @since 1.18.0
|
|
25
25
|
*/
|
|
26
|
-
export type Context<T> = T extends Guard<infer _I, infer
|
|
26
|
+
export type Context<T> = T extends Guard<infer _I, infer _O, infer _E, infer R> ? R : never
|
|
27
27
|
/**
|
|
28
28
|
* @since 1.18.0
|
|
29
29
|
*/
|
|
30
|
-
export type Error<T> = T extends Guard<infer _I, infer
|
|
30
|
+
export type Error<T> = T extends Guard<infer _I, infer _O, infer E, infer _R> ? E : never
|
|
31
31
|
/**
|
|
32
32
|
* @since 1.18.0
|
|
33
33
|
*/
|
|
34
|
-
export type Output<T> = T extends Guard<infer _I, infer
|
|
34
|
+
export type Output<T> = T extends Guard<infer _I, infer O, infer _E, infer _R> ? O : never
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
/**
|
|
38
38
|
* @since 1.18.0
|
|
39
39
|
*/
|
|
40
40
|
export const compose: {
|
|
41
|
-
<O,
|
|
42
|
-
<I,
|
|
43
|
-
} = dual(2, function flatMap<I,
|
|
44
|
-
input: Guard<I,
|
|
45
|
-
output: Guard<O,
|
|
46
|
-
): Guard<I,
|
|
41
|
+
<O, B, E2, R2>(output: Guard<O, B, E2, R2>): <I, R, E>(input: Guard<I, O, E, R>) => Guard<I, B, E | E2, R | R2>
|
|
42
|
+
<I, O, E, R, B, E2, R2>(input: Guard<I, O, E, R>, output: Guard<O, B, E2, R2>): Guard<I, B, E | E2, R | R2>
|
|
43
|
+
} = dual(2, function flatMap<I, O, E, R, B, E2, R2>(
|
|
44
|
+
input: Guard<I, O, E, R>,
|
|
45
|
+
output: Guard<O, B, E2, R2>
|
|
46
|
+
): Guard<I, B, E | E2, R | R2> {
|
|
47
47
|
return (i) =>
|
|
48
48
|
Effect.flatMap(
|
|
49
49
|
input(i),
|
|
@@ -58,14 +58,14 @@ export const compose: {
|
|
|
58
58
|
* @since 1.18.0
|
|
59
59
|
*/
|
|
60
60
|
export const mapEffect: {
|
|
61
|
-
<O,
|
|
62
|
-
f: (o: O) => Effect.Effect<
|
|
63
|
-
): <I, R, E>(guard: Guard<I,
|
|
64
|
-
<I,
|
|
65
|
-
} = dual(2, function mapEffect<I,
|
|
66
|
-
guard: Guard<I,
|
|
67
|
-
f: (o: O) => Effect.Effect<
|
|
68
|
-
): Guard<I,
|
|
61
|
+
<O, B, E2, R2>(
|
|
62
|
+
f: (o: O) => Effect.Effect<B, E2, R2>
|
|
63
|
+
): <I, R, E>(guard: Guard<I, O, E, R>) => Guard<I, B, E | E2, R | R2>
|
|
64
|
+
<I, O, E, R, B, E2, R2>(guard: Guard<I, O, E, R>, f: (o: O) => Effect.Effect<B, E2, R2>): Guard<I, B, E | E2, R | R2>
|
|
65
|
+
} = dual(2, function mapEffect<I, O, E, R, B, E2, R2>(
|
|
66
|
+
guard: Guard<I, O, E, R>,
|
|
67
|
+
f: (o: O) => Effect.Effect<B, E2, R2>
|
|
68
|
+
): Guard<I, B, E | E2, R | R2> {
|
|
69
69
|
return compose(guard, (o) => Effect.asSome(f(o)))
|
|
70
70
|
})
|
|
71
71
|
|
|
@@ -73,12 +73,12 @@ export const mapEffect: {
|
|
|
73
73
|
* @since 1.18.0
|
|
74
74
|
*/
|
|
75
75
|
export const map: {
|
|
76
|
-
<O, B>(f: (o: O) => B): <I, R, E>(guard: Guard<I,
|
|
77
|
-
<I,
|
|
78
|
-
} = dual(2, function map<I,
|
|
79
|
-
guard: Guard<I,
|
|
76
|
+
<O, B>(f: (o: O) => B): <I, R, E>(guard: Guard<I, O, E, R>) => Guard<I, B, E, R>
|
|
77
|
+
<I, O, E, R, B>(guard: Guard<I, O, E, R>, f: (o: O) => B): Guard<I, B, E, R>
|
|
78
|
+
} = dual(2, function map<I, O, E, R, B>(
|
|
79
|
+
guard: Guard<I, O, E, R>,
|
|
80
80
|
f: (o: O) => B
|
|
81
|
-
): Guard<I,
|
|
81
|
+
): Guard<I, B, E, R> {
|
|
82
82
|
return mapEffect(guard, (o) => Effect.sync(() => f(o)))
|
|
83
83
|
})
|
|
84
84
|
|
|
@@ -86,14 +86,14 @@ export const map: {
|
|
|
86
86
|
* @since 1.18.0
|
|
87
87
|
*/
|
|
88
88
|
export const tap: {
|
|
89
|
-
<O,
|
|
90
|
-
f: (o: O) => Effect.Effect<
|
|
91
|
-
): <I, R, E>(guard: Guard<I,
|
|
92
|
-
<I,
|
|
93
|
-
} = dual(2, function tap<I,
|
|
94
|
-
guard: Guard<I,
|
|
95
|
-
f: (o: O) => Effect.Effect<
|
|
96
|
-
): Guard<I,
|
|
89
|
+
<O, B, E2, R2>(
|
|
90
|
+
f: (o: O) => Effect.Effect<B, E2, R2>
|
|
91
|
+
): <I, R, E>(guard: Guard<I, O, E, R>) => Guard<I, O, E | E2, R | R2>
|
|
92
|
+
<I, O, E, R, B, E2, R2>(guard: Guard<I, O, E, R>, f: (o: O) => Effect.Effect<B, E2, R2>): Guard<I, O, E | E2, R | R2>
|
|
93
|
+
} = dual(2, function tap<I, O, E, R, B, E2, R2>(
|
|
94
|
+
guard: Guard<I, O, E, R>,
|
|
95
|
+
f: (o: O) => Effect.Effect<B, E2, R2>
|
|
96
|
+
): Guard<I, O, E | E2, R | R2> {
|
|
97
97
|
return compose(guard, (o) => Effect.as(f(o), Option.some(o)))
|
|
98
98
|
})
|
|
99
99
|
|
|
@@ -101,11 +101,11 @@ export const tap: {
|
|
|
101
101
|
* @since 1.18.0
|
|
102
102
|
*/
|
|
103
103
|
export const filterMap: {
|
|
104
|
-
<O, B>(f: (o: O) => Option.Option<B>): <I, R, E>(guard: Guard<I,
|
|
105
|
-
<I,
|
|
104
|
+
<O, B>(f: (o: O) => Option.Option<B>): <I, R, E>(guard: Guard<I, O, E, R>) => Guard<I, B, E, R>
|
|
105
|
+
<I, O, E, R, B>(guard: Guard<I, O, E, R>, f: (o: O) => Option.Option<B>): Guard<I, B, E, R>
|
|
106
106
|
} = dual(
|
|
107
107
|
2,
|
|
108
|
-
<I,
|
|
108
|
+
<I, O, E, R, B>(guard: Guard<I, O, E, R>, f: (o: O) => Option.Option<B>): Guard<I, B, E, R> => (i) =>
|
|
109
109
|
Effect.map(guard(i), Option.filterMap(f))
|
|
110
110
|
)
|
|
111
111
|
|
|
@@ -113,13 +113,13 @@ export const filterMap: {
|
|
|
113
113
|
* @since 1.18.0
|
|
114
114
|
*/
|
|
115
115
|
export const filter: {
|
|
116
|
-
<O, O2 extends O>(predicate: (o: O) => o is O2): <I, R, E>(guard: Guard<I,
|
|
117
|
-
<O>(predicate: (o: O) => boolean): <I, R, E>(guard: Guard<I,
|
|
118
|
-
<I,
|
|
119
|
-
<I,
|
|
116
|
+
<O, O2 extends O>(predicate: (o: O) => o is O2): <I, R, E>(guard: Guard<I, O, E, R>) => Guard<I, O, E, R>
|
|
117
|
+
<O>(predicate: (o: O) => boolean): <I, R, E>(guard: Guard<I, O, E, R>) => Guard<I, O, E, R>
|
|
118
|
+
<I, O, E, R, O2 extends O>(guard: Guard<I, O, E, R>, predicate: (o: O) => o is O2): Guard<I, O, E, R>
|
|
119
|
+
<I, O, E, R>(guard: Guard<I, O, E, R>, predicate: (o: O) => boolean): Guard<I, O, E, R>
|
|
120
120
|
} = dual(
|
|
121
121
|
2,
|
|
122
|
-
<I,
|
|
122
|
+
<I, O, E, R>(guard: Guard<I, O, E, R>, predicate: (o: O) => boolean): Guard<I, O, E, R> => (i) =>
|
|
123
123
|
Effect.map(guard(i), Option.filter(predicate))
|
|
124
124
|
)
|
|
125
125
|
|
|
@@ -128,7 +128,7 @@ export const filter: {
|
|
|
128
128
|
*/
|
|
129
129
|
export function any<const GS extends Readonly<Record<string, Guard<any, any, any, any>>>>(
|
|
130
130
|
guards: GS
|
|
131
|
-
): Guard<AnyInput<GS>, Guard.
|
|
131
|
+
): Guard<AnyInput<GS>, AnyOutput<GS>, Guard.Error<GS[keyof GS]>, Guard.Context<GS[keyof GS]>> {
|
|
132
132
|
const entries = Object.entries(guards)
|
|
133
133
|
return (i: AnyInput<GS>) =>
|
|
134
134
|
Effect.gen(function*(_) {
|
|
@@ -163,8 +163,8 @@ export type AnyOutput<GS extends Readonly<Record<string, Guard<any, any, any, an
|
|
|
163
163
|
/**
|
|
164
164
|
* @since 1.20.0
|
|
165
165
|
*/
|
|
166
|
-
export function liftPredicate<A, B extends A>(predicate: Predicate.Refinement<A, B>): Guard<A,
|
|
167
|
-
export function liftPredicate<A>(predicate: Predicate.Predicate<A>): Guard<A,
|
|
168
|
-
export function liftPredicate<A>(predicate: Predicate.Predicate<A>): Guard<A,
|
|
166
|
+
export function liftPredicate<A, B extends A>(predicate: Predicate.Refinement<A, B>): Guard<A, B>
|
|
167
|
+
export function liftPredicate<A>(predicate: Predicate.Predicate<A>): Guard<A, A>
|
|
168
|
+
export function liftPredicate<A>(predicate: Predicate.Predicate<A>): Guard<A, A> {
|
|
169
169
|
return (a) => Effect.sync(() => (predicate(a) ? Option.some(a) : Option.none()))
|
|
170
170
|
}
|
package/src/Idle.ts
CHANGED
|
@@ -112,7 +112,7 @@ export const defaultIdleScheduler: IdleScheduler = globalValue(
|
|
|
112
112
|
* @since 1.18.0
|
|
113
113
|
* @category combinators
|
|
114
114
|
*/
|
|
115
|
-
export const withIdleScheduler: <
|
|
115
|
+
export const withIdleScheduler: <B, E, R>(self: Effect.Effect<B, E, R>) => Effect.Effect<B, E, R> = Effect
|
|
116
116
|
.withScheduler(defaultIdleScheduler)
|
|
117
117
|
|
|
118
118
|
/**
|
|
@@ -120,14 +120,14 @@ export const withIdleScheduler: <R, E, B>(self: Effect.Effect<R, E, B>) => Effec
|
|
|
120
120
|
* @since 1.18.0
|
|
121
121
|
* @category layers
|
|
122
122
|
*/
|
|
123
|
-
export const setIdleScheduler: Layer.Layer<never
|
|
123
|
+
export const setIdleScheduler: Layer.Layer<never> = Layer.setScheduler(defaultIdleScheduler)
|
|
124
124
|
|
|
125
125
|
/**
|
|
126
126
|
* Request to run some work with requestIdleCallback returning an IdleDeadline
|
|
127
127
|
* @since 1.18.0
|
|
128
128
|
* @category scoped
|
|
129
129
|
*/
|
|
130
|
-
export const whenIdle = (options?: IdleRequestOptions): Effect.Effect<
|
|
130
|
+
export const whenIdle = (options?: IdleRequestOptions): Effect.Effect<IdleDeadline, never, Scope.Scope> =>
|
|
131
131
|
Effect.asyncEffect((resume) => {
|
|
132
132
|
const id = requestIdleCallback((deadline) => resume(Effect.succeed(deadline)), options)
|
|
133
133
|
|
|
@@ -148,8 +148,8 @@ export function shouldContinue(deadline: IdleDeadline): boolean {
|
|
|
148
148
|
* @category params
|
|
149
149
|
*/
|
|
150
150
|
export interface WhileIdleRequestOptions<R, E, R2, E2> extends IdleRequestOptions {
|
|
151
|
-
readonly while: Effect.Effect<
|
|
152
|
-
readonly body: Effect.Effect<
|
|
151
|
+
readonly while: Effect.Effect<boolean, E, R>
|
|
152
|
+
readonly body: Effect.Effect<unknown, E2, R2>
|
|
153
153
|
}
|
|
154
154
|
|
|
155
155
|
/**
|
|
@@ -158,7 +158,7 @@ export interface WhileIdleRequestOptions<R, E, R2, E2> extends IdleRequestOption
|
|
|
158
158
|
*/
|
|
159
159
|
export const whileIdle = <R, E, R2, E2>(
|
|
160
160
|
options: WhileIdleRequestOptions<R, E, R2, E2>
|
|
161
|
-
): Effect.Effect<Scope.Scope | R | R2
|
|
161
|
+
): Effect.Effect<void, E | E2, Scope.Scope | R | R2> =>
|
|
162
162
|
Effect.gen(function*(_) {
|
|
163
163
|
while (yield* _(options.while)) {
|
|
164
164
|
const deadline = yield* _(whenIdle(options))
|
|
@@ -173,29 +173,29 @@ export const whileIdle = <R, E, R2, E2>(
|
|
|
173
173
|
* Dequeue values and perform an Effect while the event loop is not busy with any other work.
|
|
174
174
|
* @since 1.18.0
|
|
175
175
|
*/
|
|
176
|
-
export function dequeueWhileIdle<A,
|
|
176
|
+
export function dequeueWhileIdle<A, B, E2, R2>(
|
|
177
177
|
dequeue: Queue.Dequeue<A>,
|
|
178
|
-
f: (a: A) => Effect.Effect<
|
|
178
|
+
f: (a: A) => Effect.Effect<B, E2, R2>,
|
|
179
179
|
options?: IdleRequestOptions
|
|
180
|
-
): Effect.Effect<R2 | Scope.Scope
|
|
180
|
+
): Effect.Effect<void, E2, R2 | Scope.Scope>
|
|
181
181
|
|
|
182
|
-
export function dequeueWhileIdle<I, A,
|
|
182
|
+
export function dequeueWhileIdle<I, A, B, E2, R2>(
|
|
183
183
|
dequeue: Context.Dequeue<I, A>,
|
|
184
|
-
f: (a: A) => Effect.Effect<
|
|
184
|
+
f: (a: A) => Effect.Effect<B, E2, R2>,
|
|
185
185
|
options?: IdleRequestOptions
|
|
186
|
-
): Effect.Effect<I | R2 | Scope.Scope
|
|
186
|
+
): Effect.Effect<void, E2, I | R2 | Scope.Scope>
|
|
187
187
|
|
|
188
188
|
export function dequeueWhileIdle<I = never, A = unknown, R2 = never, E2 = never, B = unknown>(
|
|
189
189
|
dequeue: Context.Dequeue<I, A> | Queue.Dequeue<A>,
|
|
190
|
-
f: (a: A) => Effect.Effect<
|
|
190
|
+
f: (a: A) => Effect.Effect<B, E2, R2>,
|
|
191
191
|
options?: IdleRequestOptions
|
|
192
|
-
): Effect.Effect<I | R2 | Scope.Scope
|
|
192
|
+
): Effect.Effect<void, E2, I | R2 | Scope.Scope>
|
|
193
193
|
|
|
194
|
-
export function dequeueWhileIdle<I, A,
|
|
194
|
+
export function dequeueWhileIdle<I, A, B, E2, R2>(
|
|
195
195
|
dequeue: Context.Dequeue<I, A> | Queue.Dequeue<A>,
|
|
196
|
-
f: (a: A) => Effect.Effect<
|
|
196
|
+
f: (a: A) => Effect.Effect<B, E2, R2>,
|
|
197
197
|
options?: IdleRequestOptions
|
|
198
|
-
): Effect.Effect<I | R2 | Scope.Scope
|
|
198
|
+
): Effect.Effect<void, E2, I | R2 | Scope.Scope> {
|
|
199
199
|
return whileIdle({
|
|
200
200
|
while: dequeueIsActive(dequeue),
|
|
201
201
|
body: Effect.flatMap(dequeue.take, f),
|
|
@@ -209,10 +209,10 @@ export function dequeueWhileIdle<I, A, R2, E2, B>(
|
|
|
209
209
|
export interface IdleQueue<I> {
|
|
210
210
|
readonly add: <R>(
|
|
211
211
|
part: I,
|
|
212
|
-
task: Effect.Effect<
|
|
213
|
-
) => Effect.Effect<R | Scope.Scope
|
|
212
|
+
task: Effect.Effect<unknown, never, R>
|
|
213
|
+
) => Effect.Effect<void, never, R | Scope.Scope>
|
|
214
214
|
|
|
215
|
-
readonly interrupt: Effect.Effect<
|
|
215
|
+
readonly interrupt: Effect.Effect<void>
|
|
216
216
|
}
|
|
217
217
|
|
|
218
218
|
/**
|
|
@@ -220,20 +220,20 @@ export interface IdleQueue<I> {
|
|
|
220
220
|
*/
|
|
221
221
|
export const makeIdleQueue = <I>(
|
|
222
222
|
options?: IdleRequestOptions
|
|
223
|
-
): Effect.Effect<
|
|
223
|
+
): Effect.Effect<IdleQueue<I>, never, Scope.Scope> =>
|
|
224
224
|
withScope((scope) => Effect.sync(() => new IdleQueueImpl<I>(scope, options)), ExecutionStrategy.sequential)
|
|
225
225
|
|
|
226
226
|
class IdleQueueImpl<I> implements IdleQueue<I> {
|
|
227
|
-
queue = new Map<I, Effect.Effect<
|
|
227
|
+
queue = new Map<I, Effect.Effect<unknown>>()
|
|
228
228
|
scheduled = false
|
|
229
229
|
|
|
230
|
-
readonly interrupt: Effect.Effect<
|
|
231
|
-
readonly scheduleNextRun: Effect.Effect<
|
|
230
|
+
readonly interrupt: Effect.Effect<void>
|
|
231
|
+
readonly scheduleNextRun: Effect.Effect<void>
|
|
232
232
|
|
|
233
233
|
constructor(readonly scope: Scope.CloseableScope, readonly options?: IdleRequestOptions) {
|
|
234
234
|
this.interrupt = Effect.fiberIdWith((id) => Scope.close(scope, Exit.interrupt(id)))
|
|
235
235
|
|
|
236
|
-
const run: Effect.Effect<
|
|
236
|
+
const run: Effect.Effect<void, never, Scope.Scope> = Effect.flatMap(
|
|
237
237
|
whenIdle(this.options),
|
|
238
238
|
(deadline) =>
|
|
239
239
|
Effect.gen(this, function*(_) {
|
|
@@ -274,7 +274,7 @@ class IdleQueueImpl<I> implements IdleQueue<I> {
|
|
|
274
274
|
)
|
|
275
275
|
}
|
|
276
276
|
|
|
277
|
-
add = <R>(part: I, task: Effect.Effect<
|
|
277
|
+
add = <R>(part: I, task: Effect.Effect<unknown, never, R>) =>
|
|
278
278
|
Effect.contextWithEffect((ctx: Context.Context<R>) => {
|
|
279
279
|
const provided = Effect.provide(task, ctx)
|
|
280
280
|
this.queue.set(part, provided)
|
package/src/Match.ts
CHANGED
|
@@ -33,49 +33,49 @@ export type MatcherTypeId = typeof MatcherTypeId
|
|
|
33
33
|
/**
|
|
34
34
|
* @since 1.18.0
|
|
35
35
|
*/
|
|
36
|
-
export interface TypeMatcher<
|
|
36
|
+
export interface TypeMatcher<I, O = never, E = never, R = never> {
|
|
37
37
|
readonly _tag: "TypeMatcher"
|
|
38
38
|
|
|
39
|
-
readonly [MatcherTypeId]: Matcher.Variance<
|
|
39
|
+
readonly [MatcherTypeId]: Matcher.Variance<I, O, E, R>
|
|
40
40
|
|
|
41
41
|
readonly when: <R2 = never, E2 = never, A = never, R3 = never, E3 = never, B = never>(
|
|
42
|
-
guard: Guard<I,
|
|
43
|
-
onMatch: (value: RefSubject.RefSubject<
|
|
44
|
-
) => TypeMatcher<
|
|
42
|
+
guard: Guard<I, A, E2, R2> | AsGuard<I, A, E2, R2>,
|
|
43
|
+
onMatch: (value: RefSubject.RefSubject<A>) => Fx.Fx<B, E3, R3>
|
|
44
|
+
) => TypeMatcher<I, O | B, E | E2 | E3, R | R2 | R3>
|
|
45
45
|
|
|
46
46
|
readonly to: <R2 = never, E2 = never, A = never, B = never>(
|
|
47
|
-
guard: Guard<I,
|
|
47
|
+
guard: Guard<I, A, E2, R2> | AsGuard<I, A, E2, R2>,
|
|
48
48
|
onMatch: B
|
|
49
|
-
) => TypeMatcher<
|
|
49
|
+
) => TypeMatcher<I, O | B, E | E2, R | R2>
|
|
50
50
|
|
|
51
51
|
readonly run: <R2 = never, E2 = never>(
|
|
52
|
-
input: Fx.Fx<
|
|
53
|
-
) => Fx.Fx<R | R2 | Scope.Scope
|
|
52
|
+
input: Fx.Fx<I, E2, R2>
|
|
53
|
+
) => Fx.Fx<Option.Option<O>, E | E2, R | R2 | Scope.Scope>
|
|
54
54
|
}
|
|
55
55
|
|
|
56
56
|
/**
|
|
57
57
|
* @since 1.18.0
|
|
58
58
|
*/
|
|
59
|
-
export interface ValueMatcher<
|
|
59
|
+
export interface ValueMatcher<I, O = never, E = never, R = never> extends Fx.Fx<Option.Option<O>, E, R | Scope.Scope> {
|
|
60
60
|
readonly _tag: "ValueMatcher"
|
|
61
61
|
|
|
62
|
-
readonly [MatcherTypeId]: Matcher.Variance<
|
|
62
|
+
readonly [MatcherTypeId]: Matcher.Variance<I, O, E, R>
|
|
63
63
|
|
|
64
|
-
readonly value: Fx.Fx<
|
|
64
|
+
readonly value: Fx.Fx<I, E, R>
|
|
65
65
|
|
|
66
|
-
readonly when: <
|
|
67
|
-
guard: Guard<I,
|
|
68
|
-
onMatch: (value: RefSubject.RefSubject<
|
|
69
|
-
) => ValueMatcher<
|
|
66
|
+
readonly when: <A, E2, R2, R3 = never, E3 = never, B = never>(
|
|
67
|
+
guard: Guard<I, A, E2, R2> | AsGuard<I, A, E2, R2>,
|
|
68
|
+
onMatch: (value: RefSubject.RefSubject<A>) => Fx.Fx<B, E3, R3>
|
|
69
|
+
) => ValueMatcher<I, O | B, E | E2 | E3, R | R2 | R3>
|
|
70
70
|
|
|
71
|
-
readonly to: <
|
|
72
|
-
guard: Guard<I,
|
|
71
|
+
readonly to: <A, E2, R2, B>(
|
|
72
|
+
guard: Guard<I, A, E2, R2> | AsGuard<I, A, E2, R2>,
|
|
73
73
|
onMatch: B
|
|
74
|
-
) => ValueMatcher<
|
|
74
|
+
) => ValueMatcher<I, O | B, E | E2, R | R2>
|
|
75
75
|
|
|
76
76
|
readonly getOrElse: <R2 = never, E2 = never, B = never>(
|
|
77
|
-
f: () => Fx.Fx<
|
|
78
|
-
) => Fx.Fx<
|
|
77
|
+
f: () => Fx.Fx<B, E2, R2>
|
|
78
|
+
) => Fx.Fx<O | B, E | E2, R | R2 | Scope.Scope>
|
|
79
79
|
}
|
|
80
80
|
|
|
81
81
|
/**
|
|
@@ -85,7 +85,7 @@ export namespace Matcher {
|
|
|
85
85
|
/**
|
|
86
86
|
* @since 1.18.0
|
|
87
87
|
*/
|
|
88
|
-
export interface Variance<
|
|
88
|
+
export interface Variance<I, O, E, R> {
|
|
89
89
|
readonly _R: (_: never) => R
|
|
90
90
|
readonly _E: (_: never) => E
|
|
91
91
|
readonly _I: (_: I) => unknown
|
|
@@ -96,13 +96,12 @@ export namespace Matcher {
|
|
|
96
96
|
/**
|
|
97
97
|
* @since 1.18.0
|
|
98
98
|
*/
|
|
99
|
-
export const type = <I>(): TypeMatcher<
|
|
100
|
-
new TypeMatcherImpl<never, never, I, never>(Chunk.empty())
|
|
99
|
+
export const type = <I>(): TypeMatcher<I> => new TypeMatcherImpl<I, never, never, never>(Chunk.empty())
|
|
101
100
|
|
|
102
101
|
/**
|
|
103
102
|
* @since 1.18.0
|
|
104
103
|
*/
|
|
105
|
-
export const value = <
|
|
104
|
+
export const value = <I, E = never, R = never>(input: Fx.Fx<I, E, R>): ValueMatcher<I, never, E, R> =>
|
|
106
105
|
new ValueMatcherImpl(input, type<I>())
|
|
107
106
|
|
|
108
107
|
// Internals
|
|
@@ -116,49 +115,49 @@ const variance: Matcher.Variance<any, any, any, any> = {
|
|
|
116
115
|
|
|
117
116
|
class When<R, E, I, A, O> {
|
|
118
117
|
constructor(
|
|
119
|
-
readonly guard: (input: I) => Effect.Effect<
|
|
120
|
-
readonly onMatch: (value: RefSubject.RefSubject<
|
|
118
|
+
readonly guard: (input: I) => Effect.Effect<Option.Option<A>, E, R>,
|
|
119
|
+
readonly onMatch: (value: RefSubject.RefSubject<A>) => Fx.Fx<O, E, R>
|
|
121
120
|
) {}
|
|
122
121
|
}
|
|
123
122
|
|
|
124
123
|
class Matched<R, E, I, A, O> {
|
|
125
124
|
constructor(
|
|
126
125
|
readonly when: When<R, E, I, A, O>,
|
|
127
|
-
readonly ref: RefSubject.RefSubject<
|
|
128
|
-
readonly fiber: Fiber.Fiber<
|
|
129
|
-
readonly interrupt: Effect.Effect<
|
|
126
|
+
readonly ref: RefSubject.RefSubject<A>,
|
|
127
|
+
readonly fiber: Fiber.Fiber<unknown>,
|
|
128
|
+
readonly interrupt: Effect.Effect<void>
|
|
130
129
|
) {}
|
|
131
130
|
}
|
|
132
131
|
|
|
133
|
-
class TypeMatcherImpl<
|
|
132
|
+
class TypeMatcherImpl<I, O, E, R> implements TypeMatcher<I, O, E, R> {
|
|
134
133
|
readonly _tag = "TypeMatcher"
|
|
135
|
-
readonly [MatcherTypeId]: TypeMatcher<
|
|
134
|
+
readonly [MatcherTypeId]: TypeMatcher<I, O, E, R>[MatcherTypeId] = variance as any
|
|
136
135
|
|
|
137
136
|
constructor(readonly cases: Chunk.Chunk<When<any, any, I, any, any>>) {
|
|
138
137
|
this.when = this.when.bind(this)
|
|
139
138
|
this.run = this.run.bind(this)
|
|
140
139
|
}
|
|
141
140
|
|
|
142
|
-
when<
|
|
143
|
-
guard: Guard<I,
|
|
144
|
-
onMatch: (value: RefSubject.RefSubject<
|
|
145
|
-
): TypeMatcher<
|
|
146
|
-
return new TypeMatcherImpl<
|
|
147
|
-
Chunk.append(this.cases, new When<R2 | R3, E2 | E3, I, A, B>(getGuard(guard), onMatch))
|
|
141
|
+
when<A, E2, R2, R3 = never, E3 = never, B = never>(
|
|
142
|
+
guard: Guard<I, A, E2, R2> | AsGuard<I, A, E2, R2>,
|
|
143
|
+
onMatch: (value: RefSubject.RefSubject<A>) => Fx.Fx<B, E3, R3>
|
|
144
|
+
): TypeMatcher<I, O | B, E | E2 | E3, R | R2 | R3> {
|
|
145
|
+
return new TypeMatcherImpl<I, O | B, E | E2 | E3, R | R2 | R3>(
|
|
146
|
+
Chunk.append(this.cases, new When<R | R2 | R3, E | E2 | E3, I, A, O | B>(getGuard(guard), onMatch))
|
|
148
147
|
)
|
|
149
148
|
}
|
|
150
149
|
|
|
151
|
-
to<
|
|
152
|
-
guard: Guard<I,
|
|
150
|
+
to<A, E2, R2, B>(
|
|
151
|
+
guard: Guard<I, A, E2, R2> | AsGuard<I, A, E2, R2>,
|
|
153
152
|
onMatch: B
|
|
154
|
-
): TypeMatcher<
|
|
153
|
+
): TypeMatcher<I, O | B, E | E2, R | R2> {
|
|
155
154
|
return this.when(guard, () => Fx.succeed(onMatch))
|
|
156
155
|
}
|
|
157
156
|
|
|
158
|
-
run<
|
|
157
|
+
run<E2, R2>(input: Fx.Fx<I, E2, R2>): Fx.Fx<Option.Option<O>, E | E2, R | R2 | Scope.Scope> {
|
|
159
158
|
const { cases } = this
|
|
160
159
|
|
|
161
|
-
return Fx.make<R | R2 | Scope.Scope
|
|
160
|
+
return Fx.make<Option.Option<O>, E | E2, R | R2 | Scope.Scope>((sink) =>
|
|
162
161
|
withScopedFork(
|
|
163
162
|
(fork, parentScope) => {
|
|
164
163
|
let previous: Matched<any, any, I, any, O>
|
|
@@ -182,7 +181,7 @@ class TypeMatcherImpl<R, E, I, O> implements TypeMatcher<R, E, I, O> {
|
|
|
182
181
|
// Track if the case is ended
|
|
183
182
|
const hasEnded = MutableRef.make(false)
|
|
184
183
|
// Used to signal when the case has ended
|
|
185
|
-
const endSignal = Subject.unsafeMake<
|
|
184
|
+
const endSignal = Subject.unsafeMake<void>(0)
|
|
186
185
|
|
|
187
186
|
// Run the case
|
|
188
187
|
const fiber = yield* _(
|
|
@@ -279,51 +278,51 @@ class TypeMatcherImpl<R, E, I, O> implements TypeMatcher<R, E, I, O> {
|
|
|
279
278
|
}
|
|
280
279
|
}
|
|
281
280
|
|
|
282
|
-
class ValueMatcherImpl<
|
|
283
|
-
implements ValueMatcher<
|
|
281
|
+
class ValueMatcherImpl<I, O, E, R> extends FxBase<Option.Option<O>, E, R | Scope.Scope>
|
|
282
|
+
implements ValueMatcher<I, O, E, R>
|
|
284
283
|
{
|
|
285
284
|
readonly _tag = "ValueMatcher"
|
|
286
|
-
readonly [MatcherTypeId]: ValueMatcher<
|
|
285
|
+
readonly [MatcherTypeId]: ValueMatcher<I, O, E, R>[MatcherTypeId] = variance
|
|
287
286
|
|
|
288
|
-
constructor(readonly value: Fx.Fx<
|
|
287
|
+
constructor(readonly value: Fx.Fx<I, E, R>, readonly matcher: TypeMatcher<I, O, E, R>) {
|
|
289
288
|
super()
|
|
290
289
|
this.when = this.when.bind(this)
|
|
291
290
|
this.to = this.to.bind(this)
|
|
292
291
|
this.getOrElse = this.getOrElse.bind(this)
|
|
293
292
|
}
|
|
294
293
|
|
|
295
|
-
run<R2>(sink: Sink.Sink<
|
|
294
|
+
run<R2>(sink: Sink.Sink<Option.Option<O>, E, R2>) {
|
|
296
295
|
return this.matcher.run(this.value).run(sink)
|
|
297
296
|
}
|
|
298
297
|
|
|
299
|
-
when<
|
|
300
|
-
guard: Guard<I,
|
|
301
|
-
onMatch: (value: RefSubject.RefSubject<
|
|
302
|
-
): ValueMatcher<
|
|
303
|
-
return new ValueMatcherImpl<
|
|
298
|
+
when<A, E2, R2, R3 = never, E3 = never, B = never>(
|
|
299
|
+
guard: Guard<I, A, E2, R2> | AsGuard<I, A, E2, R2>,
|
|
300
|
+
onMatch: (value: RefSubject.RefSubject<A>) => Fx.Fx<B, E3, R3>
|
|
301
|
+
): ValueMatcher<I, O | B, E | E2 | E3, R | R2 | R3> {
|
|
302
|
+
return new ValueMatcherImpl<I, O | B, E | E2 | E3, R | R2 | R3>(
|
|
304
303
|
this.value,
|
|
305
304
|
this.matcher.when(guard, onMatch)
|
|
306
305
|
)
|
|
307
306
|
}
|
|
308
307
|
|
|
309
|
-
to<
|
|
310
|
-
guard: Guard<I,
|
|
308
|
+
to<A, E2, R2, B>(
|
|
309
|
+
guard: Guard<I, A, E2, R2> | AsGuard<I, A, E2, R2>,
|
|
311
310
|
onMatch: B
|
|
312
|
-
): ValueMatcher<
|
|
311
|
+
): ValueMatcher<I, O | B, E | E2, R | R2> {
|
|
313
312
|
return this.when(guard, () => Fx.succeed(onMatch))
|
|
314
313
|
}
|
|
315
314
|
|
|
316
|
-
getOrElse: ValueMatcher<
|
|
315
|
+
getOrElse: ValueMatcher<I, O, E, R>["getOrElse"] = (f) => Fx.getOrElse(this.matcher.run(this.value), f)
|
|
317
316
|
}
|
|
318
317
|
|
|
319
318
|
/**
|
|
320
319
|
* @since 1.18.0
|
|
321
320
|
*/
|
|
322
|
-
export interface AsGuard<I,
|
|
323
|
-
readonly asGuard: () => Guard<I,
|
|
321
|
+
export interface AsGuard<I, A, E = never, R = never> {
|
|
322
|
+
readonly asGuard: () => Guard<I, A, E, R>
|
|
324
323
|
}
|
|
325
324
|
|
|
326
|
-
function getGuard<I,
|
|
325
|
+
function getGuard<I, A, E = never, R = never>(guard: Guard<I, A, E, R> | AsGuard<I, A, E, R>): Guard<I, A, E, R> {
|
|
327
326
|
if (typeof guard === "function") return guard
|
|
328
327
|
return guard.asGuard()
|
|
329
328
|
}
|