Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changing the HaltStrategy.match function signature #2202

Merged
merged 3 commits into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/real-kangaroos-push.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"effect": minor
---

The signatures of the `HaltStrategy.match` `StreamHaltStrategy.match` functions have been changed to the generally accepted ones
12 changes: 10 additions & 2 deletions packages/effect/src/ExecutionStrategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,14 @@ export const isParallelN: (self: ExecutionStrategy) => self is ParallelN = inter
* @category folding
*/
export const match: {
<A>(onSequential: LazyArg<A>, onParallel: LazyArg<A>, onParallelN: (n: number) => A): (self: ExecutionStrategy) => A
<A>(self: ExecutionStrategy, onSequential: LazyArg<A>, onParallel: LazyArg<A>, onParallelN: (n: number) => A): A
<A>(options: {
readonly onSequential: LazyArg<A>
readonly onParallel: LazyArg<A>
readonly onParallelN: (n: number) => A
}): (self: ExecutionStrategy) => A
<A>(self: ExecutionStrategy, options: {
readonly onSequential: LazyArg<A>
readonly onParallel: LazyArg<A>
readonly onParallelN: (n: number) => A
}): A
} = internal.match
16 changes: 14 additions & 2 deletions packages/effect/src/StreamHaltStrategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
<Z>(onLeft: () => Z, onRight: () => Z, onBoth: () => Z, onEither: () => Z): (self: HaltStrategy) => Z
<Z>(self: HaltStrategy, onLeft: () => Z, onRight: () => Z, onBoth: () => Z, onEither: () => Z): Z
<Z>(options: {
readonly onLeft: () => Z
readonly onRight: () => Z
readonly onBoth: () => Z
readonly onEither: () => Z
}): (self: HaltStrategy) => Z
<Z>(self: HaltStrategy, options: {
readonly onLeft: () => Z
readonly onRight: () => Z
readonly onBoth: () => Z
readonly onEither: () => Z
}): Z
} = internal.match
26 changes: 14 additions & 12 deletions packages/effect/src/internal/executionStrategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,27 +46,29 @@ export const isParallelN = (self: ExecutionStrategy.ExecutionStrategy): self is

/** @internal */
export const match = dual<
<A>(
onSequential: LazyArg<A>,
onParallel: LazyArg<A>,
onParallelN: (n: number) => A
) => (self: ExecutionStrategy.ExecutionStrategy) => A,
<A>(options: {
readonly onSequential: LazyArg<A>
readonly onParallel: LazyArg<A>
readonly onParallelN: (n: number) => A
}) => (self: ExecutionStrategy.ExecutionStrategy) => A,
<A>(
self: ExecutionStrategy.ExecutionStrategy,
onSequential: LazyArg<A>,
onParallel: LazyArg<A>,
onParallelN: (n: number) => A
options: {
readonly onSequential: LazyArg<A>
readonly onParallel: LazyArg<A>
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)
}
}
})
37 changes: 23 additions & 14 deletions packages/effect/src/internal/stream/haltStrategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,33 +53,42 @@ export const isEither = (self: HaltStrategy.HaltStrategy): self is HaltStrategy.

/** @internal */
export const match = dual<
<Z>(onLeft: () => Z, onRight: () => Z, onBoth: () => Z, onEither: () => Z) => (self: HaltStrategy.HaltStrategy) => Z,
<Z>(options: {
readonly onLeft: () => Z
readonly onRight: () => Z
readonly onBoth: () => Z
readonly onEither: () => Z
}) => (self: HaltStrategy.HaltStrategy) => Z,
<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, <Z>(
>(2, <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 => {
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()
}
}
})
Loading