diff --git a/.changeset/real-kangaroos-push.md b/.changeset/real-kangaroos-push.md new file mode 100644 index 0000000000..b01f92b2f1 --- /dev/null +++ b/.changeset/real-kangaroos-push.md @@ -0,0 +1,5 @@ +--- +"effect": minor +--- + +The signatures of the `HaltStrategy.match` `StreamHaltStrategy.match` functions have been changed to the generally accepted ones diff --git a/packages/effect/src/ExecutionStrategy.ts b/packages/effect/src/ExecutionStrategy.ts index 94cdb14956..5dba91eda7 100644 --- a/packages/effect/src/ExecutionStrategy.ts +++ b/packages/effect/src/ExecutionStrategy.ts @@ -106,6 +106,14 @@ export const isParallelN: (self: ExecutionStrategy) => self is ParallelN = inter * @category folding */ export const match: { - (onSequential: LazyArg, onParallel: LazyArg, onParallelN: (n: number) => A): (self: ExecutionStrategy) => A - (self: ExecutionStrategy, onSequential: LazyArg, onParallel: LazyArg, onParallelN: (n: number) => A): A + (options: { + readonly onSequential: LazyArg + readonly onParallel: LazyArg + readonly onParallelN: (n: number) => A + }): (self: ExecutionStrategy) => A + (self: ExecutionStrategy, options: { + readonly onSequential: LazyArg + readonly onParallel: LazyArg + readonly onParallelN: (n: number) => A + }): A } = internal.match diff --git a/packages/effect/src/StreamHaltStrategy.ts b/packages/effect/src/StreamHaltStrategy.ts index 1a582d3b78..5d7b055afb 100644 --- a/packages/effect/src/StreamHaltStrategy.ts +++ b/packages/effect/src/StreamHaltStrategy.ts @@ -102,10 +102,22 @@ export const isBoth: (self: HaltStrategy) => self is Both = internal.isBoth export const isEither: (self: HaltStrategy) => self is Either = internal.isEither /** + * Folds over the specified `HaltStrategy` using the provided case functions. + * * @since 2.0.0 * @category folding */ export const match: { - (onLeft: () => Z, onRight: () => Z, onBoth: () => Z, onEither: () => Z): (self: HaltStrategy) => Z - (self: HaltStrategy, onLeft: () => Z, onRight: () => Z, onBoth: () => Z, onEither: () => Z): Z + (options: { + readonly onLeft: () => Z + readonly onRight: () => Z + readonly onBoth: () => Z + readonly onEither: () => Z + }): (self: HaltStrategy) => Z + (self: HaltStrategy, options: { + readonly onLeft: () => Z + readonly onRight: () => Z + readonly onBoth: () => Z + readonly onEither: () => Z + }): Z } = internal.match diff --git a/packages/effect/src/internal/executionStrategy.ts b/packages/effect/src/internal/executionStrategy.ts index fbd7874029..426a0d93d2 100644 --- a/packages/effect/src/internal/executionStrategy.ts +++ b/packages/effect/src/internal/executionStrategy.ts @@ -46,27 +46,29 @@ export const isParallelN = (self: ExecutionStrategy.ExecutionStrategy): self is /** @internal */ export const match = dual< - ( - onSequential: LazyArg, - onParallel: LazyArg, - onParallelN: (n: number) => A - ) => (self: ExecutionStrategy.ExecutionStrategy) => A, + (options: { + readonly onSequential: LazyArg + readonly onParallel: LazyArg + readonly onParallelN: (n: number) => A + }) => (self: ExecutionStrategy.ExecutionStrategy) => A, ( self: ExecutionStrategy.ExecutionStrategy, - onSequential: LazyArg, - onParallel: LazyArg, - onParallelN: (n: number) => A + options: { + readonly onSequential: LazyArg + readonly onParallel: LazyArg + readonly onParallelN: (n: number) => A + } ) => A ->(4, (self, onSequential, onParallel, onParallelN) => { +>(2, (self, options) => { switch (self._tag) { case OP_SEQUENTIAL: { - return onSequential() + return options.onSequential() } case OP_PARALLEL: { - return onParallel() + return options.onParallel() } case OP_PARALLEL_N: { - return onParallelN(self.parallelism) + return options.onParallelN(self.parallelism) } } }) diff --git a/packages/effect/src/internal/stream/haltStrategy.ts b/packages/effect/src/internal/stream/haltStrategy.ts index 1ffe4dad61..0115554ef4 100644 --- a/packages/effect/src/internal/stream/haltStrategy.ts +++ b/packages/effect/src/internal/stream/haltStrategy.ts @@ -53,33 +53,42 @@ export const isEither = (self: HaltStrategy.HaltStrategy): self is HaltStrategy. /** @internal */ export const match = dual< - (onLeft: () => Z, onRight: () => Z, onBoth: () => Z, onEither: () => Z) => (self: HaltStrategy.HaltStrategy) => Z, + (options: { + readonly onLeft: () => Z + readonly onRight: () => Z + readonly onBoth: () => Z + readonly onEither: () => Z + }) => (self: HaltStrategy.HaltStrategy) => Z, ( self: HaltStrategy.HaltStrategy, - onLeft: () => Z, - onRight: () => Z, - onBoth: () => Z, - onEither: () => Z + options: { + readonly onLeft: () => Z + readonly onRight: () => Z + readonly onBoth: () => Z + readonly onEither: () => Z + } ) => Z ->(5, ( +>(2, ( self: HaltStrategy.HaltStrategy, - onLeft: () => Z, - onRight: () => Z, - onBoth: () => Z, - onEither: () => Z + options: { + readonly onLeft: () => Z + readonly onRight: () => Z + readonly onBoth: () => Z + readonly onEither: () => Z + } ): Z => { switch (self._tag) { case OpCodes.OP_LEFT: { - return onLeft() + return options.onLeft() } case OpCodes.OP_RIGHT: { - return onRight() + return options.onRight() } case OpCodes.OP_BOTH: { - return onBoth() + return options.onBoth() } case OpCodes.OP_EITHER: { - return onEither() + return options.onEither() } } })