@typed/fx 2.0.0-beta.1 → 2.0.0-beta.3
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/Fx/combinators/catch.d.ts.map +1 -1
- package/dist/Fx/combinators/unwrap.d.ts +1 -1
- package/dist/Fx/combinators/unwrap.d.ts.map +1 -1
- package/dist/Fx/run/observe.d.ts.map +1 -1
- package/dist/Fx/run/observe.js +3 -3
- package/dist/RefSubject/RefArray.d.ts.map +1 -1
- package/dist/RefSubject/RefArray.js +5 -7
- package/dist/RefSubject/RefChunk.d.ts.map +1 -1
- package/dist/RefSubject/RefChunk.js +5 -3
- package/dist/RefSubject/RefDateTime.d.ts.map +1 -1
- package/dist/RefSubject/RefDateTime.js +1 -1
- package/dist/RefSubject/RefGraph.d.ts.map +1 -1
- package/dist/RefSubject/RefGraph.js +3 -4
- package/dist/RefSubject/RefHashMap.d.ts.map +1 -1
- package/dist/RefSubject/RefHashMap.js +7 -3
- package/dist/RefSubject/RefIterable.d.ts +1 -1
- package/dist/RefSubject/RefIterable.d.ts.map +1 -1
- package/dist/RefSubject/RefIterable.js +6 -1
- package/dist/RefSubject/RefRecord.d.ts.map +1 -1
- package/dist/RefSubject/RefRecord.js +7 -9
- package/dist/RefSubject/RefSubject.d.ts +1 -1
- package/dist/RefSubject/RefSubject.d.ts.map +1 -1
- package/dist/RefSubject/RefTrie.d.ts +7 -7
- package/dist/RefSubject/RefTrie.d.ts.map +1 -1
- package/dist/RefSubject/RefTrie.js +8 -3
- package/package.json +13 -13
- package/src/Fx/combinators/catch.ts +19 -24
- package/src/Fx/combinators/unwrap.ts +1 -1
- package/src/Fx/run/observe.ts +3 -3
- package/src/RefSubject/RefArray.ts +11 -7
- package/src/RefSubject/RefChunk.ts +9 -3
- package/src/RefSubject/RefDateTime.test.ts +3 -3
- package/src/RefSubject/RefDateTime.ts +2 -5
- package/src/RefSubject/RefGraph.ts +3 -4
- package/src/RefSubject/RefHashMap.ts +12 -3
- package/src/RefSubject/RefIterable.ts +11 -2
- package/src/RefSubject/RefRecord.ts +17 -8
- package/src/RefSubject/RefSubject.ts +4 -6
- package/src/RefSubject/RefTrie.ts +19 -10
package/src/Fx/run/observe.ts
CHANGED
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
callback,
|
|
5
5
|
catchCause,
|
|
6
6
|
failCause,
|
|
7
|
-
|
|
7
|
+
forkScoped,
|
|
8
8
|
isEffect,
|
|
9
9
|
matchCauseEffect,
|
|
10
10
|
runForkWith,
|
|
@@ -84,7 +84,7 @@ export const drain = <A, E, R>(fx: Fx<A, E, R>): Effect<void, E, R> => observe(f
|
|
|
84
84
|
* @category runners
|
|
85
85
|
*/
|
|
86
86
|
export const drainLayer = <A, E, R>(fx: Fx<A, E, R>): Layer<never, E, Exclude<R, Scope>> =>
|
|
87
|
-
effectDiscard(
|
|
87
|
+
effectDiscard(forkScoped(drain(fx)));
|
|
88
88
|
|
|
89
89
|
/**
|
|
90
90
|
* Observes the values of an `Fx` stream using a callback function and returns a `Layer`.
|
|
@@ -110,5 +110,5 @@ export const observeLayer: {
|
|
|
110
110
|
<A, E, R, E2 = never, R2 = never>(
|
|
111
111
|
fx: Fx<A, E, R>,
|
|
112
112
|
f: (value: A) => void | Effect<unknown, E2, R2>,
|
|
113
|
-
): Layer<never, E | E2, Exclude<R | R2, Scope>> => effectDiscard(observe(fx, f)),
|
|
113
|
+
): Layer<never, E | E2, Exclude<R | R2, Scope>> => effectDiscard(forkScoped(observe(fx, f))),
|
|
114
114
|
);
|
|
@@ -14,6 +14,7 @@ import type * as Order from "effect/Order";
|
|
|
14
14
|
import type * as Scope from "effect/Scope";
|
|
15
15
|
import type * as Fx from "../Fx/index.js";
|
|
16
16
|
import * as RefSubject from "./RefSubject.js";
|
|
17
|
+
import { Result } from "effect";
|
|
17
18
|
|
|
18
19
|
/**
|
|
19
20
|
* A RefArray is a RefSubject that is specialized over an array of values.
|
|
@@ -210,10 +211,7 @@ export const insertAt: {
|
|
|
210
211
|
<A, E, R>(ref: RefArray<A, E, R>, index: number, a: A): Effect.Effect<ReadonlyArray<A>, E, R>;
|
|
211
212
|
} = dual(3, function insertAt<A, E, R>(ref: RefArray<A, E, R>, index: number, a: A) {
|
|
212
213
|
return RefSubject.update(ref, (as) =>
|
|
213
|
-
Option.getOrElse(
|
|
214
|
-
...as,
|
|
215
|
-
a,
|
|
216
|
-
]),
|
|
214
|
+
Option.getOrElse(ReadonlyArray.insertAt(as, index, a), () => [...as, a]),
|
|
217
215
|
);
|
|
218
216
|
});
|
|
219
217
|
|
|
@@ -291,7 +289,9 @@ export const modifyAt: {
|
|
|
291
289
|
f: (a: A) => A,
|
|
292
290
|
): Effect.Effect<ReadonlyArray<A>, E, R>;
|
|
293
291
|
} = dual(3, function modifyAt<A, E, R>(ref: RefArray<A, E, R>, index: number, f: (a: A) => A) {
|
|
294
|
-
return RefSubject.update(ref, (values) =>
|
|
292
|
+
return RefSubject.update(ref, (values) =>
|
|
293
|
+
Option.getOrElse(ReadonlyArray.modify(values, index, f), () => values),
|
|
294
|
+
);
|
|
295
295
|
});
|
|
296
296
|
|
|
297
297
|
/**
|
|
@@ -310,7 +310,9 @@ export const partition: {
|
|
|
310
310
|
predicate: (a: A) => boolean,
|
|
311
311
|
): RefSubject.Computed<never, E, readonly [ReadonlyArray<A>, ReadonlyArray<A>]>;
|
|
312
312
|
} = dual(2, function partition<A, E, R>(ref: RefArray<A, E, R>, predicate: (a: A) => boolean) {
|
|
313
|
-
return RefSubject.map(ref,
|
|
313
|
+
return RefSubject.map(ref, (array) =>
|
|
314
|
+
ReadonlyArray.partition(array, Result.liftPredicate(predicate, Result.fail)),
|
|
315
|
+
);
|
|
314
316
|
});
|
|
315
317
|
|
|
316
318
|
/**
|
|
@@ -370,7 +372,9 @@ export const replaceAt: {
|
|
|
370
372
|
<A>(index: number, a: A): <E, R>(ref: RefArray<A, E, R>) => Effect.Effect<ReadonlyArray<A>, E, R>;
|
|
371
373
|
<A, E, R>(ref: RefArray<A, E, R>, index: number, a: A): Effect.Effect<ReadonlyArray<A>, E, R>;
|
|
372
374
|
} = dual(3, function replaceAt<A, E, R>(ref: RefArray<A, E, R>, index: number, a: A) {
|
|
373
|
-
return RefSubject.update(ref, (values) =>
|
|
375
|
+
return RefSubject.update(ref, (values) =>
|
|
376
|
+
Option.getOrElse(ReadonlyArray.replace(values, index, a), () => values),
|
|
377
|
+
);
|
|
374
378
|
});
|
|
375
379
|
|
|
376
380
|
/**
|
|
@@ -8,10 +8,12 @@ import type * as Effect from "effect/Effect";
|
|
|
8
8
|
import { equals } from "effect/Equal";
|
|
9
9
|
import type { Equivalence } from "effect/Equivalence";
|
|
10
10
|
import { dual } from "effect/Function";
|
|
11
|
+
import * as Option from "effect/Option";
|
|
11
12
|
import type * as Order from "effect/Order";
|
|
12
13
|
import type * as Scope from "effect/Scope";
|
|
13
14
|
import type * as Fx from "../Fx/index.js";
|
|
14
15
|
import * as RefSubject from "./RefSubject.js";
|
|
16
|
+
import { Result } from "effect";
|
|
15
17
|
|
|
16
18
|
/**
|
|
17
19
|
* A RefChunk is a RefSubject specialized over a Chunk of values.
|
|
@@ -182,7 +184,9 @@ export const modifyAt: {
|
|
|
182
184
|
f: (a: A) => A,
|
|
183
185
|
): Effect.Effect<Chunk.Chunk<A>, E, R>;
|
|
184
186
|
} = dual(3, function modifyAt<A, E, R>(ref: RefChunk<A, E, R>, index: number, f: (a: A) => A) {
|
|
185
|
-
return RefSubject.update(ref, (chunk) =>
|
|
187
|
+
return RefSubject.update(ref, (chunk) =>
|
|
188
|
+
Option.getOrElse(Chunk.modify(chunk, index, f), () => chunk),
|
|
189
|
+
);
|
|
186
190
|
});
|
|
187
191
|
|
|
188
192
|
/**
|
|
@@ -194,7 +198,9 @@ export const replaceAt: {
|
|
|
194
198
|
<A>(index: number, a: A): <E, R>(ref: RefChunk<A, E, R>) => Effect.Effect<Chunk.Chunk<A>, E, R>;
|
|
195
199
|
<A, E, R>(ref: RefChunk<A, E, R>, index: number, a: A): Effect.Effect<Chunk.Chunk<A>, E, R>;
|
|
196
200
|
} = dual(3, function replaceAt<A, E, R>(ref: RefChunk<A, E, R>, index: number, a: A) {
|
|
197
|
-
return RefSubject.update(ref, (chunk) =>
|
|
201
|
+
return RefSubject.update(ref, (chunk) =>
|
|
202
|
+
Option.getOrElse(Chunk.replace(chunk, index, a), () => chunk),
|
|
203
|
+
);
|
|
198
204
|
});
|
|
199
205
|
|
|
200
206
|
/**
|
|
@@ -356,7 +362,7 @@ export const partition: {
|
|
|
356
362
|
predicate: (a: A) => boolean,
|
|
357
363
|
): RefSubject.Computed<[Chunk.Chunk<A>, Chunk.Chunk<A>], E, R>;
|
|
358
364
|
} = dual(2, function partition<A, E, R>(ref: RefChunk<A, E, R>, predicate: (a: A) => boolean) {
|
|
359
|
-
return RefSubject.map(ref, Chunk.partition(predicate));
|
|
365
|
+
return RefSubject.map(ref, Chunk.partition(Result.liftPredicate(predicate, Result.fail)));
|
|
360
366
|
});
|
|
361
367
|
|
|
362
368
|
/**
|
|
@@ -10,21 +10,21 @@ describe("RefDateTime", () => {
|
|
|
10
10
|
const value = DateTime.nowUnsafe();
|
|
11
11
|
const ref = yield* RefDateTime.make(value);
|
|
12
12
|
const current = yield* ref;
|
|
13
|
-
expect(current
|
|
13
|
+
expect(DateTime.toEpochMillis(current)).toBe(DateTime.toEpochMillis(value));
|
|
14
14
|
}).pipe(Effect.scoped, Effect.runPromise));
|
|
15
15
|
|
|
16
16
|
it("adds duration", () =>
|
|
17
17
|
Effect.gen(function* () {
|
|
18
18
|
const ref = yield* RefDateTime.make(DateTime.makeUnsafe(0));
|
|
19
19
|
const result = yield* RefDateTime.addDuration(ref, Duration.seconds(5));
|
|
20
|
-
expect(result
|
|
20
|
+
expect(DateTime.toEpochMillis(result)).toBe(5000);
|
|
21
21
|
}).pipe(Effect.scoped, Effect.runPromise));
|
|
22
22
|
|
|
23
23
|
it("subtracts duration", () =>
|
|
24
24
|
Effect.gen(function* () {
|
|
25
25
|
const ref = yield* RefDateTime.make(DateTime.makeUnsafe(10000));
|
|
26
26
|
const result = yield* RefDateTime.subtractDuration(ref, Duration.seconds(3));
|
|
27
|
-
expect(result
|
|
27
|
+
expect(DateTime.toEpochMillis(result)).toBe(7000);
|
|
28
28
|
}).pipe(Effect.scoped, Effect.runPromise));
|
|
29
29
|
|
|
30
30
|
it("gets epoch milliseconds", () =>
|
|
@@ -183,10 +183,7 @@ export const subtractDuration: {
|
|
|
183
183
|
ref: RefDateTime<E, R>,
|
|
184
184
|
duration: Duration.Input,
|
|
185
185
|
): RefSubject.Computed<DateTime.DateTime, E, R>;
|
|
186
|
-
} = dual(2, function subtractDuration<
|
|
187
|
-
E,
|
|
188
|
-
R,
|
|
189
|
-
>(ref: RefDateTime<E, R>, duration: Duration.Input) {
|
|
186
|
+
} = dual(2, function subtractDuration<E, R>(ref: RefDateTime<E, R>, duration: Duration.Input) {
|
|
190
187
|
return RefSubject.map(ref, (self) => DateTime.subtractDuration(self, duration));
|
|
191
188
|
});
|
|
192
189
|
|
|
@@ -196,7 +193,7 @@ export const subtractDuration: {
|
|
|
196
193
|
* @category computed
|
|
197
194
|
*/
|
|
198
195
|
export const epochMillis = <E, R>(ref: RefDateTime<E, R>): RefSubject.Computed<number, E, R> =>
|
|
199
|
-
RefSubject.map(ref, (self) => self
|
|
196
|
+
RefSubject.map(ref, (self) => DateTime.toEpochMillis(self));
|
|
200
197
|
|
|
201
198
|
/**
|
|
202
199
|
* Format the current state of a RefDateTime.
|
|
@@ -7,7 +7,6 @@ import type * as Effect from "effect/Effect";
|
|
|
7
7
|
import { equals } from "effect/Equal";
|
|
8
8
|
import { dual } from "effect/Function";
|
|
9
9
|
import * as Graph from "effect/Graph";
|
|
10
|
-
import * as Option from "effect/Option";
|
|
11
10
|
import type * as Scope from "effect/Scope";
|
|
12
11
|
import type * as Fx from "../Fx/index.js";
|
|
13
12
|
import * as RefSubject from "./RefSubject.js";
|
|
@@ -596,7 +595,7 @@ export const getEdge: {
|
|
|
596
595
|
Err,
|
|
597
596
|
R,
|
|
598
597
|
>(ref: RefGraph<N, E, T, Err, R>, edgeIndex: Graph.EdgeIndex) {
|
|
599
|
-
return RefSubject.filterMap(ref, (g) =>
|
|
598
|
+
return RefSubject.filterMap(ref, (g) => Graph.getEdge(g, edgeIndex));
|
|
600
599
|
});
|
|
601
600
|
|
|
602
601
|
/**
|
|
@@ -621,7 +620,7 @@ export const findNode: {
|
|
|
621
620
|
Err,
|
|
622
621
|
R,
|
|
623
622
|
>(ref: RefGraph<N, E, T, Err, R>, predicate: (data: N) => boolean) {
|
|
624
|
-
return RefSubject.filterMap(ref, (g) =>
|
|
623
|
+
return RefSubject.filterMap(ref, (g) => Graph.findNode(g, predicate));
|
|
625
624
|
});
|
|
626
625
|
|
|
627
626
|
/**
|
|
@@ -646,5 +645,5 @@ export const findEdge: {
|
|
|
646
645
|
Err,
|
|
647
646
|
R,
|
|
648
647
|
>(ref: RefGraph<N, E, T, Err, R>, predicate: (edge: E) => boolean) {
|
|
649
|
-
return RefSubject.filterMap(ref, (g) =>
|
|
648
|
+
return RefSubject.filterMap(ref, (g) => Graph.findEdge(g, predicate));
|
|
650
649
|
});
|
|
@@ -5,12 +5,13 @@
|
|
|
5
5
|
|
|
6
6
|
import type * as Effect from "effect/Effect";
|
|
7
7
|
import { equals } from "effect/Equal";
|
|
8
|
-
import { dual
|
|
8
|
+
import { dual } from "effect/Function";
|
|
9
9
|
import * as HashMap from "effect/HashMap";
|
|
10
10
|
import * as Option from "effect/Option";
|
|
11
11
|
import type * as Scope from "effect/Scope";
|
|
12
12
|
import type * as Fx from "../Fx/index.js";
|
|
13
13
|
import * as RefSubject from "./RefSubject.js";
|
|
14
|
+
import { Result } from "effect";
|
|
14
15
|
|
|
15
16
|
/**
|
|
16
17
|
* A RefHashMap is a RefSubject specialized over a HashMap.
|
|
@@ -354,7 +355,15 @@ export const filterMapValues: {
|
|
|
354
355
|
R,
|
|
355
356
|
B,
|
|
356
357
|
>(ref: RefHashMap<K, V, E, R>, f: (value: V, key: K) => Option.Option<B>) {
|
|
357
|
-
return RefSubject.map(
|
|
358
|
+
return RefSubject.map(
|
|
359
|
+
ref,
|
|
360
|
+
HashMap.filterMap((value, key) =>
|
|
361
|
+
Option.match(f(value, key), {
|
|
362
|
+
onNone: () => Result.failVoid,
|
|
363
|
+
onSome: (b) => Result.succeed(b),
|
|
364
|
+
}),
|
|
365
|
+
),
|
|
366
|
+
);
|
|
358
367
|
});
|
|
359
368
|
|
|
360
369
|
/**
|
|
@@ -461,5 +470,5 @@ export const findFirst: {
|
|
|
461
470
|
E,
|
|
462
471
|
R,
|
|
463
472
|
>(ref: RefHashMap<K, V, E, R>, predicate: (value: V, key: K) => boolean) {
|
|
464
|
-
return RefSubject.filterMap(ref,
|
|
473
|
+
return RefSubject.filterMap(ref, (g) => HashMap.findFirst(g, predicate));
|
|
465
474
|
});
|
|
@@ -3,11 +3,12 @@
|
|
|
3
3
|
* @since 1.18.0
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
+
import { Result } from "effect";
|
|
6
7
|
import type * as Effect from "effect/Effect";
|
|
7
8
|
import { equals } from "effect/Equal";
|
|
8
9
|
import { dual } from "effect/Function";
|
|
9
10
|
import * as Iterable from "effect/Iterable";
|
|
10
|
-
import
|
|
11
|
+
import * as Option from "effect/Option";
|
|
11
12
|
import type * as Scope from "effect/Scope";
|
|
12
13
|
import type * as Fx from "../Fx/index.js";
|
|
13
14
|
import * as RefSubject from "./RefSubject.js";
|
|
@@ -233,7 +234,15 @@ export const filterMap: {
|
|
|
233
234
|
E,
|
|
234
235
|
R,
|
|
235
236
|
>(ref: RefIterable<A, E, R>, f: (a: A, index: number) => Option.Option<A>) {
|
|
236
|
-
return RefSubject.update(
|
|
237
|
+
return RefSubject.update(
|
|
238
|
+
ref,
|
|
239
|
+
Iterable.filterMap((a, index) =>
|
|
240
|
+
Option.match(f(a, index), {
|
|
241
|
+
onNone: () => Result.failVoid,
|
|
242
|
+
onSome: (b) => Result.succeed(b),
|
|
243
|
+
}),
|
|
244
|
+
),
|
|
245
|
+
);
|
|
237
246
|
});
|
|
238
247
|
|
|
239
248
|
/**
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
* @since 1.18.0
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
+
import { Result } from "effect";
|
|
6
7
|
import type * as Effect from "effect/Effect";
|
|
7
8
|
import { equals } from "effect/Equal";
|
|
8
9
|
import { dual } from "effect/Function";
|
|
@@ -99,7 +100,7 @@ export const modify: {
|
|
|
99
100
|
E,
|
|
100
101
|
R,
|
|
101
102
|
>(ref: RefRecord<K, V, E, R>, key: K, f: (v: V) => V) {
|
|
102
|
-
return RefSubject.update(ref, (r) => Record.modify(r, key, f)
|
|
103
|
+
return RefSubject.update(ref, (r) => Option.getOrElse(Record.modify(r, key, f), () => r));
|
|
103
104
|
});
|
|
104
105
|
|
|
105
106
|
/**
|
|
@@ -123,7 +124,7 @@ export const replace: {
|
|
|
123
124
|
E,
|
|
124
125
|
R,
|
|
125
126
|
>(ref: RefRecord<K, V, E, R>, key: K, value: V) {
|
|
126
|
-
return RefSubject.update(ref, (r) => Record.replace(r, key, value)
|
|
127
|
+
return RefSubject.update(ref, (r) => Option.getOrElse(Record.replace(r, key, value), () => r));
|
|
127
128
|
});
|
|
128
129
|
|
|
129
130
|
/**
|
|
@@ -450,7 +451,11 @@ export const filterMapValues: {
|
|
|
450
451
|
R,
|
|
451
452
|
B,
|
|
452
453
|
>(ref: RefRecord<K, V, E, R>, f: (value: V, key: K) => Option.Option<B>) {
|
|
453
|
-
return RefSubject.map(ref, (r) =>
|
|
454
|
+
return RefSubject.map(ref, (r) =>
|
|
455
|
+
Record.filterMap(r, (value, key) =>
|
|
456
|
+
f(value, key) ? Result.succeed(value) : Result.fail(value),
|
|
457
|
+
),
|
|
458
|
+
);
|
|
454
459
|
});
|
|
455
460
|
|
|
456
461
|
/**
|
|
@@ -477,7 +482,9 @@ export const partition: {
|
|
|
477
482
|
return RefSubject.map(
|
|
478
483
|
ref,
|
|
479
484
|
(r) =>
|
|
480
|
-
Record.partition(r,
|
|
485
|
+
Record.partition(r, (value, key) =>
|
|
486
|
+
predicate(value, key) ? Result.succeed(value) : Result.fail(value),
|
|
487
|
+
) as [Record.ReadonlyRecord<K, V>, Record.ReadonlyRecord<K, V>],
|
|
481
488
|
);
|
|
482
489
|
});
|
|
483
490
|
|
|
@@ -585,7 +592,7 @@ export const findFirst: {
|
|
|
585
592
|
E,
|
|
586
593
|
R,
|
|
587
594
|
>(ref: RefRecord<K, V, E, R>, predicate: (value: V, key: K) => boolean) {
|
|
588
|
-
return RefSubject.filterMap(ref, (r) =>
|
|
595
|
+
return RefSubject.filterMap(ref, (r) => Record.findFirst(r, predicate));
|
|
589
596
|
});
|
|
590
597
|
|
|
591
598
|
/**
|
|
@@ -605,8 +612,10 @@ export const pop: {
|
|
|
605
612
|
): RefSubject.Filtered<[V, Record.ReadonlyRecord<K, V>], E, R>;
|
|
606
613
|
} = dual(2, function pop<K extends string, V, E, R>(ref: RefRecord<K, V, E, R>, key: K) {
|
|
607
614
|
return RefSubject.filterMap(ref, (r) => {
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
615
|
+
return Option.map(
|
|
616
|
+
Record.pop(r, key),
|
|
617
|
+
([value, next]) =>
|
|
618
|
+
[value, next as Record.ReadonlyRecord<K, V>] as [V, Record.ReadonlyRecord<K, V>],
|
|
619
|
+
);
|
|
611
620
|
});
|
|
612
621
|
});
|
|
@@ -1240,12 +1240,10 @@ export const runUpdates: {
|
|
|
1240
1240
|
<A, E, R, B, E2, R2, R3 = never, E3 = never, C = never>(
|
|
1241
1241
|
ref: RefSubject<A, E, R>,
|
|
1242
1242
|
f: (ref: GetSetDelete<A, E, R>) => Effect.Effect<B, E2, R2>,
|
|
1243
|
-
options?:
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
}
|
|
1248
|
-
| undefined,
|
|
1243
|
+
options?: {
|
|
1244
|
+
readonly onInterrupt: (value: A) => Effect.Effect<C, E3, R3>;
|
|
1245
|
+
readonly value?: "initial" | "current";
|
|
1246
|
+
},
|
|
1249
1247
|
): Effect.Effect<B, E | E2 | E3, R | R2 | R3>;
|
|
1250
1248
|
} = dual(
|
|
1251
1249
|
isRefSubjectDataFirst,
|
|
@@ -6,11 +6,12 @@
|
|
|
6
6
|
import type * as Effect from "effect/Effect";
|
|
7
7
|
import { equals } from "effect/Equal";
|
|
8
8
|
import { dual } from "effect/Function";
|
|
9
|
-
import
|
|
9
|
+
import * as Option from "effect/Option";
|
|
10
10
|
import type * as Scope from "effect/Scope";
|
|
11
11
|
import * as Trie from "effect/Trie";
|
|
12
12
|
import type * as Fx from "../Fx/index.js";
|
|
13
13
|
import * as RefSubject from "./RefSubject.js";
|
|
14
|
+
import { Result } from "effect";
|
|
14
15
|
|
|
15
16
|
/**
|
|
16
17
|
* A RefTrie is a RefSubject specialized over a Trie.
|
|
@@ -122,13 +123,13 @@ export const clear = <V, E, R>(ref: RefTrie<V, E, R>): Effect.Effect<Trie.Trie<V
|
|
|
122
123
|
export const map: {
|
|
123
124
|
<V>(
|
|
124
125
|
f: (value: V, key: string) => V,
|
|
125
|
-
): <E, R>(ref: RefTrie<V, E, R>) =>
|
|
126
|
+
): <E, R>(ref: RefTrie<V, E, R>) => RefSubject.Computed<Trie.Trie<V>, E, R>;
|
|
126
127
|
<V, E, R>(
|
|
127
128
|
ref: RefTrie<V, E, R>,
|
|
128
129
|
f: (value: V, key: string) => V,
|
|
129
|
-
):
|
|
130
|
+
): RefSubject.Computed<Trie.Trie<V>, E, R>;
|
|
130
131
|
} = dual(2, function map<V, E, R>(ref: RefTrie<V, E, R>, f: (value: V, key: string) => V) {
|
|
131
|
-
return RefSubject.
|
|
132
|
+
return RefSubject.map(ref, Trie.map(f));
|
|
132
133
|
});
|
|
133
134
|
|
|
134
135
|
/**
|
|
@@ -139,17 +140,17 @@ export const map: {
|
|
|
139
140
|
export const filter: {
|
|
140
141
|
<V>(
|
|
141
142
|
predicate: (value: V, key: string) => boolean,
|
|
142
|
-
): <E, R>(ref: RefTrie<V, E, R>) =>
|
|
143
|
+
): <E, R>(ref: RefTrie<V, E, R>) => RefSubject.Computed<Trie.Trie<V>, E, R>;
|
|
143
144
|
<V, E, R>(
|
|
144
145
|
ref: RefTrie<V, E, R>,
|
|
145
146
|
predicate: (value: V, key: string) => boolean,
|
|
146
|
-
):
|
|
147
|
+
): RefSubject.Computed<Trie.Trie<V>, E, R>;
|
|
147
148
|
} = dual(2, function filter<
|
|
148
149
|
V,
|
|
149
150
|
E,
|
|
150
151
|
R,
|
|
151
152
|
>(ref: RefTrie<V, E, R>, predicate: (value: V, key: string) => boolean) {
|
|
152
|
-
return RefSubject.
|
|
153
|
+
return RefSubject.map(ref, Trie.filter(predicate));
|
|
153
154
|
});
|
|
154
155
|
|
|
155
156
|
/**
|
|
@@ -160,17 +161,25 @@ export const filter: {
|
|
|
160
161
|
export const filterMap: {
|
|
161
162
|
<V>(
|
|
162
163
|
f: (value: V, key: string) => Option.Option<V>,
|
|
163
|
-
): <E, R>(ref: RefTrie<V, E, R>) =>
|
|
164
|
+
): <E, R>(ref: RefTrie<V, E, R>) => RefSubject.Computed<Trie.Trie<V>, E, R>;
|
|
164
165
|
<V, E, R>(
|
|
165
166
|
ref: RefTrie<V, E, R>,
|
|
166
167
|
f: (value: V, key: string) => Option.Option<V>,
|
|
167
|
-
):
|
|
168
|
+
): RefSubject.Computed<Trie.Trie<V>, E, R>;
|
|
168
169
|
} = dual(2, function filterMap<
|
|
169
170
|
V,
|
|
170
171
|
E,
|
|
171
172
|
R,
|
|
172
173
|
>(ref: RefTrie<V, E, R>, f: (value: V, key: string) => Option.Option<V>) {
|
|
173
|
-
return RefSubject.
|
|
174
|
+
return RefSubject.map(
|
|
175
|
+
ref,
|
|
176
|
+
Trie.filterMap((value, key) =>
|
|
177
|
+
Option.match(f(value, key), {
|
|
178
|
+
onNone: () => Result.failVoid,
|
|
179
|
+
onSome: (b) => Result.succeed(b),
|
|
180
|
+
}),
|
|
181
|
+
),
|
|
182
|
+
);
|
|
174
183
|
});
|
|
175
184
|
|
|
176
185
|
// ========================================
|