effect 4.0.0-beta.17 → 4.0.0-beta.19
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/Array.d.ts +127 -299
- package/dist/Array.d.ts.map +1 -1
- package/dist/Array.js +102 -62
- package/dist/Array.js.map +1 -1
- package/dist/Cache.d.ts.map +1 -1
- package/dist/Cache.js +5 -4
- package/dist/Cache.js.map +1 -1
- package/dist/Channel.d.ts +97 -11
- package/dist/Channel.d.ts.map +1 -1
- package/dist/Channel.js +72 -29
- package/dist/Channel.js.map +1 -1
- package/dist/Chunk.d.ts +54 -247
- package/dist/Chunk.d.ts.map +1 -1
- package/dist/Chunk.js +36 -67
- package/dist/Chunk.js.map +1 -1
- package/dist/Effect.d.ts +337 -437
- package/dist/Effect.d.ts.map +1 -1
- package/dist/Effect.js +118 -134
- package/dist/Effect.js.map +1 -1
- package/dist/Filter.d.ts +0 -33
- package/dist/Filter.d.ts.map +1 -1
- package/dist/Filter.js +0 -13
- package/dist/Filter.js.map +1 -1
- package/dist/HashMap.d.ts +15 -14
- package/dist/HashMap.d.ts.map +1 -1
- package/dist/HashMap.js +4 -4
- package/dist/HashMap.js.map +1 -1
- package/dist/Iterable.d.ts +40 -39
- package/dist/Iterable.d.ts.map +1 -1
- package/dist/Iterable.js +94 -22
- package/dist/Iterable.js.map +1 -1
- package/dist/Option.d.ts +22 -15
- package/dist/Option.d.ts.map +1 -1
- package/dist/Option.js +14 -7
- package/dist/Option.js.map +1 -1
- package/dist/Pull.d.ts.map +1 -1
- package/dist/Pull.js +1 -1
- package/dist/Pull.js.map +1 -1
- package/dist/Record.d.ts +24 -120
- package/dist/Record.d.ts.map +1 -1
- package/dist/Record.js +21 -41
- package/dist/Record.js.map +1 -1
- package/dist/Sink.d.ts +11 -11
- package/dist/Sink.d.ts.map +1 -1
- package/dist/Sink.js +53 -6
- package/dist/Sink.js.map +1 -1
- package/dist/Stream.d.ts +198 -386
- package/dist/Stream.d.ts.map +1 -1
- package/dist/Stream.js +103 -59
- package/dist/Stream.js.map +1 -1
- package/dist/Trie.d.ts +18 -17
- package/dist/Trie.d.ts.map +1 -1
- package/dist/Trie.js +5 -5
- package/dist/Trie.js.map +1 -1
- package/dist/TxChunk.d.ts +37 -37
- package/dist/TxChunk.d.ts.map +1 -1
- package/dist/TxChunk.js +3 -3
- package/dist/TxChunk.js.map +1 -1
- package/dist/TxDeferred.d.ts +328 -0
- package/dist/TxDeferred.d.ts.map +1 -0
- package/dist/TxDeferred.js +196 -0
- package/dist/TxDeferred.js.map +1 -0
- package/dist/TxHashMap.d.ts +84 -83
- package/dist/TxHashMap.d.ts.map +1 -1
- package/dist/TxHashMap.js +24 -24
- package/dist/TxHashMap.js.map +1 -1
- package/dist/TxHashSet.d.ts +35 -35
- package/dist/TxHashSet.d.ts.map +1 -1
- package/dist/TxHashSet.js +14 -14
- package/dist/TxHashSet.js.map +1 -1
- package/dist/TxPriorityQueue.d.ts +609 -0
- package/dist/TxPriorityQueue.d.ts.map +1 -0
- package/dist/TxPriorityQueue.js +415 -0
- package/dist/TxPriorityQueue.js.map +1 -0
- package/dist/TxPubSub.d.ts +585 -0
- package/dist/TxPubSub.d.ts.map +1 -0
- package/dist/TxPubSub.js +521 -0
- package/dist/TxPubSub.js.map +1 -0
- package/dist/TxQueue.d.ts +32 -32
- package/dist/TxQueue.d.ts.map +1 -1
- package/dist/TxQueue.js +26 -26
- package/dist/TxQueue.js.map +1 -1
- package/dist/TxReentrantLock.d.ts +523 -0
- package/dist/TxReentrantLock.d.ts.map +1 -0
- package/dist/TxReentrantLock.js +504 -0
- package/dist/TxReentrantLock.js.map +1 -0
- package/dist/TxRef.d.ts +34 -34
- package/dist/TxRef.d.ts.map +1 -1
- package/dist/TxRef.js +21 -14
- package/dist/TxRef.js.map +1 -1
- package/dist/TxSemaphore.d.ts +8 -8
- package/dist/TxSemaphore.d.ts.map +1 -1
- package/dist/TxSemaphore.js +7 -7
- package/dist/TxSemaphore.js.map +1 -1
- package/dist/TxSubscriptionRef.d.ts +508 -0
- package/dist/TxSubscriptionRef.d.ts.map +1 -0
- package/dist/TxSubscriptionRef.js +293 -0
- package/dist/TxSubscriptionRef.js.map +1 -0
- package/dist/index.d.ts +40 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +40 -0
- package/dist/index.js.map +1 -1
- package/dist/internal/effect.js +99 -42
- package/dist/internal/effect.js.map +1 -1
- package/dist/internal/hashMap.js +3 -2
- package/dist/internal/hashMap.js.map +1 -1
- package/dist/internal/trie.js +5 -4
- package/dist/internal/trie.js.map +1 -1
- package/dist/unstable/ai/Tool.d.ts.map +1 -1
- package/dist/unstable/ai/Tool.js +0 -9
- package/dist/unstable/ai/Tool.js.map +1 -1
- package/dist/unstable/cli/Command.d.ts +1 -1
- package/dist/unstable/cli/Command.d.ts.map +1 -1
- package/dist/unstable/cli/Command.js +1 -1
- package/dist/unstable/cli/Command.js.map +1 -1
- package/dist/unstable/cluster/K8sHttpClient.js +4 -4
- package/dist/unstable/cluster/K8sHttpClient.js.map +1 -1
- package/dist/unstable/cluster/Sharding.js +1 -1
- package/dist/unstable/cluster/Sharding.js.map +1 -1
- package/dist/unstable/encoding/Sse.js +1 -1
- package/dist/unstable/encoding/Sse.js.map +1 -1
- package/dist/unstable/rpc/RpcServer.d.ts.map +1 -1
- package/dist/unstable/rpc/RpcServer.js +1 -2
- package/dist/unstable/rpc/RpcServer.js.map +1 -1
- package/dist/unstable/socket/Socket.d.ts.map +1 -1
- package/dist/unstable/socket/Socket.js +3 -3
- package/dist/unstable/socket/Socket.js.map +1 -1
- package/package.json +1 -1
- package/src/Array.ts +190 -342
- package/src/Cache.ts +6 -5
- package/src/Channel.ts +506 -102
- package/src/Chunk.ts +81 -268
- package/src/Effect.ts +437 -518
- package/src/Filter.ts +0 -57
- package/src/HashMap.ts +15 -14
- package/src/Iterable.ts +105 -50
- package/src/Option.ts +30 -20
- package/src/Pull.ts +1 -1
- package/src/Record.ts +43 -152
- package/src/Sink.ts +75 -23
- package/src/Stream.ts +442 -502
- package/src/Trie.ts +18 -17
- package/src/TxChunk.ts +72 -53
- package/src/TxDeferred.ts +394 -0
- package/src/TxHashMap.ts +332 -285
- package/src/TxHashSet.ts +111 -116
- package/src/TxPriorityQueue.ts +767 -0
- package/src/TxPubSub.ts +789 -0
- package/src/TxQueue.ts +241 -251
- package/src/TxReentrantLock.ts +753 -0
- package/src/TxRef.ts +50 -38
- package/src/TxSemaphore.ts +29 -32
- package/src/TxSubscriptionRef.ts +639 -0
- package/src/index.ts +45 -0
- package/src/internal/effect.ts +368 -163
- package/src/internal/hashMap.ts +7 -5
- package/src/internal/trie.ts +16 -9
- package/src/unstable/ai/Tool.ts +0 -9
- package/src/unstable/cli/Command.ts +6 -4
- package/src/unstable/cluster/K8sHttpClient.ts +4 -4
- package/src/unstable/cluster/Sharding.ts +1 -1
- package/src/unstable/encoding/Sse.ts +1 -1
- package/src/unstable/rpc/RpcServer.ts +1 -7
- package/src/unstable/socket/Socket.ts +9 -11
package/dist/Stream.js
CHANGED
|
@@ -12,7 +12,6 @@ import * as Equal from "./Equal.js";
|
|
|
12
12
|
import * as ExecutionPlan from "./ExecutionPlan.js";
|
|
13
13
|
import * as Exit from "./Exit.js";
|
|
14
14
|
import * as Fiber from "./Fiber.js";
|
|
15
|
-
import * as Filter from "./Filter.js";
|
|
16
15
|
import { constant, constTrue, constVoid, dual, identity } from "./Function.js";
|
|
17
16
|
import * as internalExecutionPlan from "./internal/executionPlan.js";
|
|
18
17
|
import * as internal from "./internal/stream.js";
|
|
@@ -2808,19 +2807,22 @@ export const race = /*#__PURE__*/dual(2, (left, right) => raceAll(left, right));
|
|
|
2808
2807
|
* @since 2.0.0
|
|
2809
2808
|
* @category Filtering
|
|
2810
2809
|
*/
|
|
2811
|
-
export const filter = /*#__PURE__*/dual(2, (self,
|
|
2810
|
+
export const filter = /*#__PURE__*/dual(2, (self, predicate) => fromChannel(Channel.filterArray(toChannel(self), predicate)));
|
|
2812
2811
|
/**
|
|
2813
|
-
*
|
|
2812
|
+
* Filters and maps stream elements in one pass using a `Filter`.
|
|
2813
|
+
*
|
|
2814
|
+
* @since 4.0.0
|
|
2815
|
+
* @category Filtering
|
|
2816
|
+
*/
|
|
2817
|
+
export const filterMap = /*#__PURE__*/dual(2, (self, filter) => fromChannel(Channel.filterMapArray(toChannel(self), filter)));
|
|
2818
|
+
/**
|
|
2819
|
+
* Effectfully filters elements in a single pass.
|
|
2814
2820
|
*
|
|
2815
2821
|
* @example
|
|
2816
2822
|
* ```ts
|
|
2817
|
-
* import { Console, Effect,
|
|
2818
|
-
*
|
|
2819
|
-
* const filter = Filter.makeEffect((n: number) =>
|
|
2820
|
-
* Effect.succeed(n > 2 ? Result.succeed(n + 1) : Result.fail(n))
|
|
2821
|
-
* )
|
|
2823
|
+
* import { Console, Effect, Stream } from "effect"
|
|
2822
2824
|
*
|
|
2823
|
-
* const stream = Stream.make(1, 2, 3, 4).pipe(Stream.filterEffect(
|
|
2825
|
+
* const stream = Stream.make(1, 2, 3, 4).pipe(Stream.filterEffect((n) => Effect.succeed(n > 2)))
|
|
2824
2826
|
*
|
|
2825
2827
|
* const program = Effect.gen(function*() {
|
|
2826
2828
|
* const result = yield* Stream.runCollect(stream)
|
|
@@ -2828,27 +2830,32 @@ export const filter = /*#__PURE__*/dual(2, (self, filter) => fromChannel(Channel
|
|
|
2828
2830
|
* })
|
|
2829
2831
|
*
|
|
2830
2832
|
* Effect.runPromise(program)
|
|
2831
|
-
* // Output: [
|
|
2833
|
+
* // Output: [ 3, 4 ]
|
|
2832
2834
|
* ```
|
|
2833
2835
|
*
|
|
2834
2836
|
* @since 2.0.0
|
|
2835
2837
|
* @category Filtering
|
|
2836
2838
|
*/
|
|
2837
|
-
export const filterEffect = /*#__PURE__*/dual(2, (self,
|
|
2839
|
+
export const filterEffect = /*#__PURE__*/dual(2, (self, predicate) => fromChannel(Channel.filterArrayEffect(toChannel(self), predicate)));
|
|
2838
2840
|
/**
|
|
2839
|
-
*
|
|
2841
|
+
* Effectfully filters and maps elements in a single pass.
|
|
2842
|
+
*
|
|
2843
|
+
* @since 4.0.0
|
|
2844
|
+
* @category Filtering
|
|
2845
|
+
*/
|
|
2846
|
+
export const filterMapEffect = /*#__PURE__*/dual(2, (self, filter) => fromChannel(Channel.filterMapArrayEffect(toChannel(self), filter)));
|
|
2847
|
+
/**
|
|
2848
|
+
* Partitions a stream using a `Filter` and exposes passing and failing values as queues.
|
|
2840
2849
|
*
|
|
2841
2850
|
* Each queue fails with the stream error or `Cause.Done` when the source ends.
|
|
2842
2851
|
*
|
|
2843
2852
|
* @example
|
|
2844
2853
|
* ```ts
|
|
2845
|
-
* import { Console, Effect,
|
|
2854
|
+
* import { Console, Effect, Result, Stream } from "effect"
|
|
2846
2855
|
*
|
|
2847
2856
|
* const program = Effect.gen(function*() {
|
|
2848
2857
|
* const [passes, fails] = yield* Stream.make(1, 2, 3, 4).pipe(
|
|
2849
|
-
* Stream.partitionQueue(
|
|
2850
|
-
* Filter.make((n) => (n % 2 === 0 ? Result.succeed(n) : Result.fail(n)))
|
|
2851
|
-
* )
|
|
2858
|
+
* Stream.partitionQueue((n) => n % 2 === 0 ? Result.succeed(n) : Result.fail(n))
|
|
2852
2859
|
* )
|
|
2853
2860
|
*
|
|
2854
2861
|
* const passValues = yield* Stream.fromQueue(passes).pipe(Stream.runCollect)
|
|
@@ -2876,11 +2883,19 @@ export const partitionQueue = /*#__PURE__*/dual(args => isStream(args[0]), /*#__
|
|
|
2876
2883
|
const fails = yield* Queue.make({
|
|
2877
2884
|
capacity
|
|
2878
2885
|
});
|
|
2879
|
-
const partitionArr = Arr.partition(filter);
|
|
2880
2886
|
yield* Effect.gen(function* () {
|
|
2881
2887
|
while (true) {
|
|
2882
2888
|
const chunk = yield* pull;
|
|
2883
|
-
const
|
|
2889
|
+
const excluded = [];
|
|
2890
|
+
const satisfying = [];
|
|
2891
|
+
for (let i = 0; i < chunk.length; i++) {
|
|
2892
|
+
const result = filter(chunk[i]);
|
|
2893
|
+
if (Result.isFailure(result)) {
|
|
2894
|
+
excluded.push(result.failure);
|
|
2895
|
+
} else {
|
|
2896
|
+
satisfying.push(result.success);
|
|
2897
|
+
}
|
|
2898
|
+
}
|
|
2884
2899
|
let passFiber = undefined;
|
|
2885
2900
|
if (satisfying.length > 0) {
|
|
2886
2901
|
const leftover = Queue.offerAllUnsafe(passes, satisfying);
|
|
@@ -2904,38 +2919,14 @@ export const partitionQueue = /*#__PURE__*/dual(args => isStream(args[0]), /*#__
|
|
|
2904
2919
|
return [passes, fails];
|
|
2905
2920
|
}));
|
|
2906
2921
|
/**
|
|
2907
|
-
* Splits a stream using an effectful
|
|
2922
|
+
* Splits a stream using an effectful `Filter`, producing pass and fail streams.
|
|
2908
2923
|
*
|
|
2909
2924
|
* @since 4.0.0
|
|
2910
2925
|
* @category Filtering
|
|
2911
|
-
*
|
|
2912
|
-
* @example
|
|
2913
|
-
* ```ts
|
|
2914
|
-
* import { Console, Effect, Result, Stream } from "effect"
|
|
2915
|
-
*
|
|
2916
|
-
* const program = Effect.scoped(
|
|
2917
|
-
* Effect.gen(function*() {
|
|
2918
|
-
* const [evens, odds] = yield* Stream.make(1, 2, 3, 4).pipe(
|
|
2919
|
-
* Stream.partitionEffect((n) =>
|
|
2920
|
-
* Effect.succeed(n % 2 === 0 ? Result.succeed(n) : Result.fail(n))
|
|
2921
|
-
* )
|
|
2922
|
-
* )
|
|
2923
|
-
* const result = yield* Effect.all({
|
|
2924
|
-
* evens: Stream.runCollect(evens),
|
|
2925
|
-
* odds: Stream.runCollect(odds)
|
|
2926
|
-
* })
|
|
2927
|
-
* yield* Console.log(result)
|
|
2928
|
-
* })
|
|
2929
|
-
* )
|
|
2930
|
-
*
|
|
2931
|
-
* Effect.runPromise(program)
|
|
2932
|
-
* // Output: { evens: [ 2, 4 ], odds: [ 1, 3 ] }
|
|
2933
|
-
* ```
|
|
2934
2926
|
*/
|
|
2935
|
-
export const partitionEffect = /*#__PURE__*/dual(args => isStream(args[0]), (self, filter, options) => Effect.map(
|
|
2927
|
+
export const partitionEffect = /*#__PURE__*/dual(args => isStream(args[0]), (self, filter, options) => Effect.map(partitionQueue(mapEffect(self, a => filter(a), options), result => result, options), ([passes, fails]) => [fromQueue(passes), fromQueue(fails)]));
|
|
2936
2928
|
/**
|
|
2937
|
-
* Splits a stream into excluded and satisfying substreams using a
|
|
2938
|
-
* refinement, or Filter.
|
|
2929
|
+
* Splits a stream into excluded and satisfying substreams using a `Filter`.
|
|
2939
2930
|
*
|
|
2940
2931
|
* The faster stream may advance up to `bufferSize` elements ahead of the slower
|
|
2941
2932
|
* one.
|
|
@@ -2945,12 +2936,12 @@ export const partitionEffect = /*#__PURE__*/dual(args => isStream(args[0]), (sel
|
|
|
2945
2936
|
*
|
|
2946
2937
|
* @example
|
|
2947
2938
|
* ```ts
|
|
2948
|
-
* import { Console, Effect, Stream } from "effect"
|
|
2939
|
+
* import { Console, Effect, Result, Stream } from "effect"
|
|
2949
2940
|
*
|
|
2950
2941
|
* const program = Effect.gen(function*() {
|
|
2951
2942
|
* const [excluded, satisfying] = yield* Stream.partition(
|
|
2952
2943
|
* Stream.make(1, 2, 3, 4),
|
|
2953
|
-
* (n) => n % 2 === 0
|
|
2944
|
+
* (n) => n % 2 === 0 ? Result.succeed(n) : Result.fail(n)
|
|
2954
2945
|
* )
|
|
2955
2946
|
* const left = yield* Stream.runCollect(excluded)
|
|
2956
2947
|
* const right = yield* Stream.runCollect(satisfying)
|
|
@@ -2961,9 +2952,9 @@ export const partitionEffect = /*#__PURE__*/dual(args => isStream(args[0]), (sel
|
|
|
2961
2952
|
* })
|
|
2962
2953
|
* ```
|
|
2963
2954
|
*/
|
|
2964
|
-
export const partition = /*#__PURE__*/dual(args => isStream(args[0]), (self, filter, options) => Effect.map(partitionQueue(filter, {
|
|
2955
|
+
export const partition = /*#__PURE__*/dual(args => isStream(args[0]), (self, filter, options) => Effect.map(partitionQueue(self, filter, {
|
|
2965
2956
|
capacity: options?.bufferSize ?? 16
|
|
2966
|
-
})
|
|
2957
|
+
}), ([passes, fails]) => [fromQueue(fails), fromQueue(passes)]));
|
|
2967
2958
|
/**
|
|
2968
2959
|
* Returns the specified stream if the given condition is satisfied, otherwise
|
|
2969
2960
|
* returns an empty stream.
|
|
@@ -3219,7 +3210,7 @@ catch_ as catch };
|
|
|
3219
3210
|
*/
|
|
3220
3211
|
export const tapError = /*#__PURE__*/dual(2, (self, f) => self.channel.pipe(Channel.tapError(f), fromChannel));
|
|
3221
3212
|
/**
|
|
3222
|
-
* Recovers from errors that match a
|
|
3213
|
+
* Recovers from errors that match a predicate by switching to a recovery stream.
|
|
3223
3214
|
*
|
|
3224
3215
|
* When a failure matches the filter, the stream switches to the recovery
|
|
3225
3216
|
* stream. Non-matching failures propagate downstream, so the error type is
|
|
@@ -3233,12 +3224,12 @@ export const tapError = /*#__PURE__*/dual(2, (self, f) => self.channel.pipe(Chan
|
|
|
3233
3224
|
*
|
|
3234
3225
|
* @example
|
|
3235
3226
|
* ```ts
|
|
3236
|
-
* import { Console, Effect,
|
|
3227
|
+
* import { Console, Effect, Stream } from "effect"
|
|
3237
3228
|
*
|
|
3238
3229
|
* const stream = Stream.make(1, 2).pipe(
|
|
3239
3230
|
* Stream.concat(Stream.fail(42)),
|
|
3240
3231
|
* Stream.catchIf(
|
|
3241
|
-
*
|
|
3232
|
+
* (error): error is 42 => error === 42,
|
|
3242
3233
|
* () => Stream.make(999)
|
|
3243
3234
|
* )
|
|
3244
3235
|
* )
|
|
@@ -3255,7 +3246,15 @@ export const tapError = /*#__PURE__*/dual(2, (self, f) => self.channel.pipe(Chan
|
|
|
3255
3246
|
* @since 4.0.0
|
|
3256
3247
|
* @category Error Handling
|
|
3257
3248
|
*/
|
|
3258
|
-
export const catchIf = /*#__PURE__*/dual(args => isStream(args[0]), (self,
|
|
3249
|
+
export const catchIf = /*#__PURE__*/dual(args => isStream(args[0]), (self, predicate, f, orElse) => fromChannel(Channel.catchIf(toChannel(self), predicate, e => f(e).channel, orElse && (e => orElse(e).channel))));
|
|
3250
|
+
/**
|
|
3251
|
+
* Recovers from errors that match a `Filter` by switching to a recovery
|
|
3252
|
+
* stream.
|
|
3253
|
+
*
|
|
3254
|
+
* @since 4.0.0
|
|
3255
|
+
* @category Error Handling
|
|
3256
|
+
*/
|
|
3257
|
+
export const catchFilter = /*#__PURE__*/dual(args => isStream(args[0]), (self, filter, f, orElse) => fromChannel(Channel.catchFilter(toChannel(self), filter, e => f(e).channel, orElse && (e => orElse(e).channel))));
|
|
3259
3258
|
/**
|
|
3260
3259
|
* Recovers from failures whose `_tag` matches the provided value by switching to
|
|
3261
3260
|
* the stream returned by `f`.
|
|
@@ -3331,7 +3330,7 @@ export const catchTag = /*#__PURE__*/dual(args => isStream(args[0]), (self, k, f
|
|
|
3331
3330
|
*/
|
|
3332
3331
|
export const catchTags = /*#__PURE__*/dual(args => isStream(args[0]), (self, cases, orElse) => {
|
|
3333
3332
|
let keys;
|
|
3334
|
-
return
|
|
3333
|
+
return catchFilter(self, e => {
|
|
3335
3334
|
keys ??= Object.keys(cases);
|
|
3336
3335
|
return hasProperty(e, "_tag") && isString(e["_tag"]) && keys.includes(e["_tag"]) ? Result.succeed(e) : Result.fail(e);
|
|
3337
3336
|
}, e => cases[e["_tag"]](e), orElse);
|
|
@@ -3487,7 +3486,15 @@ export const mapError = /*#__PURE__*/dual(2, (self, f) => fromChannel(Channel.ma
|
|
|
3487
3486
|
* @since 4.0.0
|
|
3488
3487
|
* @category Error Handling
|
|
3489
3488
|
*/
|
|
3490
|
-
export const catchCauseIf = /*#__PURE__*/dual(3, (self,
|
|
3489
|
+
export const catchCauseIf = /*#__PURE__*/dual(3, (self, predicate, f) => fromChannel(Channel.catchCauseIf(self.channel, predicate, cause => f(cause).channel)));
|
|
3490
|
+
/**
|
|
3491
|
+
* Recovers from stream failures by filtering the `Cause` and switching to a
|
|
3492
|
+
* recovery stream.
|
|
3493
|
+
*
|
|
3494
|
+
* @since 4.0.0
|
|
3495
|
+
* @category Error Handling
|
|
3496
|
+
*/
|
|
3497
|
+
export const catchCauseFilter = /*#__PURE__*/dual(3, (self, filter, f) => fromChannel(Channel.catchCauseFilter(self.channel, filter, (failure, cause) => f(failure, cause).channel)));
|
|
3491
3498
|
/**
|
|
3492
3499
|
* Switches to a fallback stream if this stream is empty.
|
|
3493
3500
|
*
|
|
@@ -3901,13 +3908,34 @@ export const takeUntilEffect = /*#__PURE__*/dual(args => isStream(args[0]), (sel
|
|
|
3901
3908
|
* @since 2.0.0
|
|
3902
3909
|
* @category Filtering
|
|
3903
3910
|
*/
|
|
3904
|
-
export const takeWhile = /*#__PURE__*/dual(2, (self,
|
|
3911
|
+
export const takeWhile = /*#__PURE__*/dual(2, (self, predicate) => transformPull(self, (pull, _scope) => Effect.sync(() => {
|
|
3905
3912
|
let i = 0;
|
|
3906
3913
|
let done = false;
|
|
3907
3914
|
const pump = Effect.flatMap(Effect.suspend(() => done ? Cause.done() : pull), chunk => {
|
|
3908
3915
|
const out = [];
|
|
3909
3916
|
for (let j = 0; j < chunk.length; j++) {
|
|
3910
|
-
|
|
3917
|
+
if (!predicate(chunk[j], i++)) {
|
|
3918
|
+
done = true;
|
|
3919
|
+
break;
|
|
3920
|
+
}
|
|
3921
|
+
out.push(chunk[j]);
|
|
3922
|
+
}
|
|
3923
|
+
return Arr.isReadonlyArrayNonEmpty(out) ? Effect.succeed(out) : done ? Cause.done() : pump;
|
|
3924
|
+
});
|
|
3925
|
+
return pump;
|
|
3926
|
+
})));
|
|
3927
|
+
/**
|
|
3928
|
+
* Takes the longest initial prefix of elements that satisfy the filter.
|
|
3929
|
+
*
|
|
3930
|
+
* @since 4.0.0
|
|
3931
|
+
* @category Filtering
|
|
3932
|
+
*/
|
|
3933
|
+
export const takeWhileFilter = /*#__PURE__*/dual(2, (self, filter) => transformPull(self, (pull, _scope) => Effect.sync(() => {
|
|
3934
|
+
let done = false;
|
|
3935
|
+
const pump = Effect.flatMap(Effect.suspend(() => done ? Cause.done() : pull), chunk => {
|
|
3936
|
+
const out = [];
|
|
3937
|
+
for (let j = 0; j < chunk.length; j++) {
|
|
3938
|
+
const result = filter(chunk[j]);
|
|
3911
3939
|
if (Result.isFailure(result)) {
|
|
3912
3940
|
done = true;
|
|
3913
3941
|
break;
|
|
@@ -4044,11 +4072,27 @@ export const dropUntilEffect = /*#__PURE__*/dual(2, (self, predicate) => drop(dr
|
|
|
4044
4072
|
* @since 2.0.0
|
|
4045
4073
|
* @category Filtering
|
|
4046
4074
|
*/
|
|
4047
|
-
export const dropWhile = /*#__PURE__*/dual(2, (self,
|
|
4075
|
+
export const dropWhile = /*#__PURE__*/dual(2, (self, predicate) => transformPull(self, (pull, _scope) => Effect.sync(() => {
|
|
4048
4076
|
let dropping = true;
|
|
4049
4077
|
let index = 0;
|
|
4050
4078
|
const filtered = Effect.flatMap(pull, arr => {
|
|
4051
|
-
const found = arr.findIndex(a =>
|
|
4079
|
+
const found = arr.findIndex(a => !predicate(a, index++));
|
|
4080
|
+
if (found === -1) return filtered;
|
|
4081
|
+
dropping = false;
|
|
4082
|
+
return Effect.succeed(arr.slice(found));
|
|
4083
|
+
});
|
|
4084
|
+
return Effect.suspend(() => dropping ? filtered : pull);
|
|
4085
|
+
})));
|
|
4086
|
+
/**
|
|
4087
|
+
* Drops elements while the filter succeeds.
|
|
4088
|
+
*
|
|
4089
|
+
* @since 4.0.0
|
|
4090
|
+
* @category Filtering
|
|
4091
|
+
*/
|
|
4092
|
+
export const dropWhileFilter = /*#__PURE__*/dual(2, (self, filter) => transformPull(self, (pull, _scope) => Effect.sync(() => {
|
|
4093
|
+
let dropping = true;
|
|
4094
|
+
const filtered = Effect.flatMap(pull, arr => {
|
|
4095
|
+
const found = arr.findIndex(a => Result.isFailure(filter(a)));
|
|
4052
4096
|
if (found === -1) return filtered;
|
|
4053
4097
|
dropping = false;
|
|
4054
4098
|
return Effect.succeed(arr.slice(found));
|