@typed/fx 1.23.0 → 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/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/keyed.js.map +1 -1
- package/dist/cjs/internal/provide.js.map +1 -1
- package/dist/dts/AsyncData.d.ts +36 -36
- package/dist/dts/AsyncData.d.ts.map +1 -1
- package/dist/dts/Emitter.d.ts +2 -2
- package/dist/dts/Form.d.ts +6 -6
- package/dist/dts/Form.d.ts.map +1 -1
- package/dist/dts/FormEntry.d.ts +8 -8
- package/dist/dts/Fx.d.ts +414 -414
- 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 +3 -3
- 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 +127 -127
- package/dist/dts/RefSubject.d.ts.map +1 -1
- package/dist/dts/Sink.d.ts +60 -60
- 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 +10 -10
- 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 +28 -28
- package/dist/dts/Versioned.d.ts.map +1 -1
- package/dist/dts/index.d.ts +1 -1
- package/dist/dts/internal/DeferredRef.d.ts +1 -1
- 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 +2 -2
- package/dist/dts/internal/effect-loop-operator.d.ts.map +1 -1
- package/dist/dts/internal/effect-operator.d.ts +9 -9
- package/dist/dts/internal/effect-operator.d.ts.map +1 -1
- package/dist/dts/internal/effect-producer.d.ts +10 -10
- package/dist/dts/internal/effect-producer.d.ts.map +1 -1
- package/dist/dts/internal/helpers.d.ts +16 -16
- 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 +7 -7
- package/dist/dts/internal/protos.d.ts.map +1 -1
- package/dist/dts/internal/provide.d.ts +10 -10
- package/dist/dts/internal/provide.d.ts.map +1 -1
- package/dist/dts/internal/share.d.ts +10 -10
- 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 +4 -4
- 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/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/keyed.js.map +1 -1
- package/dist/esm/internal/provide.js.map +1 -1
- package/package.json +2 -2
- package/src/AsyncData.ts +71 -73
- package/src/Emitter.ts +5 -5
- package/src/Form.ts +27 -27
- package/src/FormEntry.ts +29 -29
- package/src/Fx.ts +735 -734
- package/src/Guard.ts +39 -39
- package/src/Idle.ts +4 -4
- package/src/Match.ts +57 -58
- package/src/Pull.ts +35 -36
- package/src/Push.ts +170 -170
- package/src/RefArray.ts +114 -112
- package/src/RefChunk.ts +93 -92
- package/src/RefHashMap.ts +71 -71
- package/src/RefHashSet.ts +40 -39
- package/src/RefSubject.ts +437 -428
- package/src/Sink.ts +235 -235
- package/src/Stream.ts +20 -20
- package/src/Subject.ts +34 -32
- package/src/Typeclass.ts +2 -2
- package/src/Versioned.ts +75 -75
- package/src/index.ts +1 -1
- package/src/internal/DeferredRef.ts +1 -1
- package/src/internal/core.ts +688 -701
- package/src/internal/effect-loop-operator.ts +3 -3
- package/src/internal/effect-operator.ts +12 -12
- package/src/internal/effect-producer.ts +25 -25
- package/src/internal/helpers.ts +18 -18
- package/src/internal/keyed.ts +18 -18
- package/src/internal/loop-operator.ts +2 -2
- package/src/internal/operator.ts +2 -2
- package/src/internal/protos.ts +8 -8
- package/src/internal/provide.ts +19 -19
- package/src/internal/share.ts +22 -22
- package/src/internal/sync-operator.ts +4 -4
- package/src/internal/sync-producer.ts +6 -6
- 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,
|
|
61
|
+
<O, B, E2, R2>(
|
|
62
62
|
f: (o: O) => Effect.Effect<B, E2, R2>
|
|
63
|
-
): <I, R, E>(guard: Guard<I,
|
|
64
|
-
<I,
|
|
65
|
-
} = dual(2, function mapEffect<I,
|
|
66
|
-
guard: Guard<I,
|
|
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
67
|
f: (o: O) => Effect.Effect<B, E2, R2>
|
|
68
|
-
): Guard<I,
|
|
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,
|
|
89
|
+
<O, B, E2, R2>(
|
|
90
90
|
f: (o: O) => Effect.Effect<B, E2, R2>
|
|
91
|
-
): <I, R, E>(guard: Guard<I,
|
|
92
|
-
<I,
|
|
93
|
-
} = dual(2, function tap<I,
|
|
94
|
-
guard: Guard<I,
|
|
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
95
|
f: (o: O) => Effect.Effect<B, E2, R2>
|
|
96
|
-
): Guard<I,
|
|
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
|
/**
|
|
@@ -173,13 +173,13 @@ 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
178
|
f: (a: A) => Effect.Effect<B, E2, R2>,
|
|
179
179
|
options?: IdleRequestOptions
|
|
180
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
184
|
f: (a: A) => Effect.Effect<B, E2, R2>,
|
|
185
185
|
options?: IdleRequestOptions
|
|
@@ -191,7 +191,7 @@ export function dequeueWhileIdle<I = never, A = unknown, R2 = never, E2 = never,
|
|
|
191
191
|
options?: IdleRequestOptions
|
|
192
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
196
|
f: (a: A) => Effect.Effect<B, E2, R2>,
|
|
197
197
|
options?: IdleRequestOptions
|
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
|
|
@@ -117,48 +116,48 @@ const variance: Matcher.Variance<any, any, any, any> = {
|
|
|
117
116
|
class When<R, E, I, A, O> {
|
|
118
117
|
constructor(
|
|
119
118
|
readonly guard: (input: I) => Effect.Effect<Option.Option<A>, E, R>,
|
|
120
|
-
readonly onMatch: (value: RefSubject.RefSubject<
|
|
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<
|
|
126
|
+
readonly ref: RefSubject.RefSubject<A>,
|
|
128
127
|
readonly fiber: Fiber.Fiber<unknown>,
|
|
129
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
|
}
|
package/src/Pull.ts
CHANGED
|
@@ -19,28 +19,27 @@ import type { Sink } from "./Sink.js"
|
|
|
19
19
|
* An Effect which can be used to pull values of a Stream.
|
|
20
20
|
* @since 1.18.0
|
|
21
21
|
*/
|
|
22
|
-
export interface Pull<out
|
|
22
|
+
export interface Pull<out A, out E = never, out R = never> extends Effect.Effect<Chunk.Chunk<A>, Option.Option<E>, R> {}
|
|
23
23
|
|
|
24
|
-
function schedulePull<
|
|
25
|
-
pull: Pull<
|
|
24
|
+
function schedulePull<A, E, R, R2, R3>(
|
|
25
|
+
pull: Pull<A, E, R>,
|
|
26
26
|
f: (effect: Effect.Effect<unknown, never, R | R3>) => Effect.Effect<unknown, never, R2>,
|
|
27
|
-
sink: Sink<
|
|
27
|
+
sink: Sink<A, E, R3>
|
|
28
28
|
): Effect.Effect<void, never, R2> {
|
|
29
29
|
return Effect.asyncEffect<void, never, never, void, never, R2>((resume) =>
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
}),
|
|
30
|
+
Effect.matchCauseEffect(pull, {
|
|
31
|
+
onFailure: (cause: Cause.Cause<Option.Option<E>>) =>
|
|
32
|
+
Cause.failureOrCause(cause).pipe(
|
|
33
|
+
Either.match({
|
|
34
|
+
onLeft: Option.match({
|
|
35
|
+
onNone: () => Effect.sync(() => resume(Effect.unit)),
|
|
36
|
+
onSome: (e: E) => sink.onFailure(Cause.fail(e))
|
|
37
|
+
}),
|
|
38
|
+
onRight: sink.onFailure
|
|
39
|
+
})
|
|
40
|
+
),
|
|
41
|
+
onSuccess: (chunk: Chunk.Chunk<A>) => Effect.forEach(chunk, sink.onSuccess, { discard: true })
|
|
42
|
+
}).pipe(
|
|
44
43
|
f,
|
|
45
44
|
Effect.flatMap(() => Effect.sync(() => resume(Effect.unit)))
|
|
46
45
|
)
|
|
@@ -53,20 +52,20 @@ function schedulePull<R, E, A, R2, R3>(
|
|
|
53
52
|
* @since 1.18.0
|
|
54
53
|
*/
|
|
55
54
|
export const schedule: {
|
|
56
|
-
<R2,
|
|
55
|
+
<R2, A, E, R3>(
|
|
57
56
|
schedule: Schedule.Schedule<R2, unknown, unknown>,
|
|
58
|
-
sink: Sink<
|
|
59
|
-
): <R>(pull: Pull<
|
|
57
|
+
sink: Sink<A, E, R3>
|
|
58
|
+
): <R>(pull: Pull<A, E, R>) => Effect.Effect<unknown, never, R | R2 | R3>
|
|
60
59
|
|
|
61
|
-
<
|
|
62
|
-
pull: Pull<
|
|
60
|
+
<A, E, R, R2, R3>(
|
|
61
|
+
pull: Pull<A, E, R>,
|
|
63
62
|
schedule: Schedule.Schedule<R2, unknown, unknown>,
|
|
64
|
-
sink: Sink<
|
|
63
|
+
sink: Sink<A, E, R3>
|
|
65
64
|
): Effect.Effect<unknown, never, R | R2 | R3>
|
|
66
|
-
} = dual(3, function schedule<
|
|
67
|
-
pull: Pull<
|
|
65
|
+
} = dual(3, function schedule<A, E, R, R2, R3>(
|
|
66
|
+
pull: Pull<A, E, R>,
|
|
68
67
|
schedule: Schedule.Schedule<R2, unknown, unknown>,
|
|
69
|
-
sink: Sink<
|
|
68
|
+
sink: Sink<A, E, R3>
|
|
70
69
|
): Effect.Effect<void, never, R | R2 | R3> {
|
|
71
70
|
return schedulePull(pull, Effect.schedule(schedule), sink)
|
|
72
71
|
})
|
|
@@ -77,20 +76,20 @@ export const schedule: {
|
|
|
77
76
|
* @since 1.18.0
|
|
78
77
|
*/
|
|
79
78
|
export const repeat: {
|
|
80
|
-
<R2,
|
|
79
|
+
<R2, A, E, R3>(
|
|
81
80
|
schedule: Schedule.Schedule<R2, unknown, unknown>,
|
|
82
|
-
sink: Sink<
|
|
83
|
-
): <R>(pull: Pull<
|
|
81
|
+
sink: Sink<A, E, R3>
|
|
82
|
+
): <R>(pull: Pull<A, E, R>) => Effect.Effect<unknown, never, R | R2 | R3>
|
|
84
83
|
|
|
85
|
-
<
|
|
86
|
-
pull: Pull<
|
|
84
|
+
<A, E, R, R2, R3>(
|
|
85
|
+
pull: Pull<A, E, R>,
|
|
87
86
|
schedule: Schedule.Schedule<R2, unknown, unknown>,
|
|
88
|
-
sink: Sink<
|
|
87
|
+
sink: Sink<A, E, R3>
|
|
89
88
|
): Effect.Effect<unknown, never, R | R2 | R3>
|
|
90
|
-
} = dual(3, function repeat<
|
|
91
|
-
pull: Pull<
|
|
89
|
+
} = dual(3, function repeat<A, E, R, R2, R3>(
|
|
90
|
+
pull: Pull<A, E, R>,
|
|
92
91
|
schedule: Schedule.Schedule<R2, unknown, unknown>,
|
|
93
|
-
sink: Sink<
|
|
92
|
+
sink: Sink<A, E, R3>
|
|
94
93
|
): Effect.Effect<void, never, R | R2 | R3> {
|
|
95
94
|
return schedulePull(pull, Effect.repeat(schedule), sink)
|
|
96
95
|
})
|