Skip to content

Commit

Permalink
Merge branch 'Effect-TS:next-minor' into next-minor
Browse files Browse the repository at this point in the history
  • Loading branch information
KhraksMamtsov authored Mar 1, 2024
2 parents de74eb8 + 52ec4ca commit ab02fbd
Show file tree
Hide file tree
Showing 8 changed files with 99 additions and 56 deletions.
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
5 changes: 5 additions & 0 deletions .changeset/sharp-bears-sing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"effect": minor
---

Fix ConfigError `_tag`, with the previous implementation catching the `ConfigError` with `Effect.catchTag` would show `And`, `Or`, etc.
13 changes: 7 additions & 6 deletions packages/effect/src/ConfigError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export declare namespace ConfigError {
* @category models
*/
export interface Proto {
readonly _tag: "ConfigError"
readonly [ConfigErrorTypeId]: ConfigErrorTypeId
}

Expand Down Expand Up @@ -72,7 +73,7 @@ export interface ConfigErrorReducer<in C, in out Z> {
* @category models
*/
export interface And extends ConfigError.Proto {
readonly _tag: "And"
readonly _op: "And"
readonly left: ConfigError
readonly right: ConfigError
}
Expand All @@ -82,7 +83,7 @@ export interface And extends ConfigError.Proto {
* @category models
*/
export interface Or extends ConfigError.Proto {
readonly _tag: "Or"
readonly _op: "Or"
readonly left: ConfigError
readonly right: ConfigError
}
Expand All @@ -92,7 +93,7 @@ export interface Or extends ConfigError.Proto {
* @category models
*/
export interface InvalidData extends ConfigError.Proto {
readonly _tag: "InvalidData"
readonly _op: "InvalidData"
readonly path: Array<string>
readonly message: string
}
Expand All @@ -102,7 +103,7 @@ export interface InvalidData extends ConfigError.Proto {
* @category models
*/
export interface MissingData extends ConfigError.Proto {
readonly _tag: "MissingData"
readonly _op: "MissingData"
readonly path: Array<string>
readonly message: string
}
Expand All @@ -112,7 +113,7 @@ export interface MissingData extends ConfigError.Proto {
* @category models
*/
export interface SourceUnavailable extends ConfigError.Proto {
readonly _tag: "SourceUnavailable"
readonly _op: "SourceUnavailable"
readonly path: Array<string>
readonly message: string
readonly cause: Cause.Cause<unknown>
Expand All @@ -123,7 +124,7 @@ export interface SourceUnavailable extends ConfigError.Proto {
* @category models
*/
export interface Unsupported extends ConfigError.Proto {
readonly _tag: "Unsupported"
readonly _op: "Unsupported"
readonly path: Array<string>
readonly message: string
}
Expand Down
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
41 changes: 21 additions & 20 deletions packages/effect/src/internal/configError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@ export const ConfigErrorTypeId: ConfigError.ConfigErrorTypeId = Symbol.for(

/** @internal */
export const proto = {
_tag: "ConfigError",
[ConfigErrorTypeId]: ConfigErrorTypeId
}

/** @internal */
export const And = (self: ConfigError.ConfigError, that: ConfigError.ConfigError): ConfigError.ConfigError => {
const error = Object.create(proto)
error._tag = OpCodes.OP_AND
error._op = OpCodes.OP_AND
error.left = self
error.right = that
Object.defineProperty(error, "toString", {
Expand All @@ -37,7 +38,7 @@ export const And = (self: ConfigError.ConfigError, that: ConfigError.ConfigError
/** @internal */
export const Or = (self: ConfigError.ConfigError, that: ConfigError.ConfigError): ConfigError.ConfigError => {
const error = Object.create(proto)
error._tag = OpCodes.OP_OR
error._op = OpCodes.OP_OR
error.left = self
error.right = that
Object.defineProperty(error, "toString", {
Expand All @@ -56,7 +57,7 @@ export const InvalidData = (
options: ConfigError.Options = { pathDelim: "." }
): ConfigError.ConfigError => {
const error = Object.create(proto)
error._tag = OpCodes.OP_INVALID_DATA
error._op = OpCodes.OP_INVALID_DATA
error.path = path
error.message = message
Object.defineProperty(error, "toString", {
Expand All @@ -76,7 +77,7 @@ export const MissingData = (
options: ConfigError.Options = { pathDelim: "." }
): ConfigError.ConfigError => {
const error = Object.create(proto)
error._tag = OpCodes.OP_MISSING_DATA
error._op = OpCodes.OP_MISSING_DATA
error.path = path
error.message = message
Object.defineProperty(error, "toString", {
Expand All @@ -97,7 +98,7 @@ export const SourceUnavailable = (
options: ConfigError.Options = { pathDelim: "." }
): ConfigError.ConfigError => {
const error = Object.create(proto)
error._tag = OpCodes.OP_SOURCE_UNAVAILABLE
error._op = OpCodes.OP_SOURCE_UNAVAILABLE
error.path = path
error.message = message
error.cause = cause
Expand All @@ -118,7 +119,7 @@ export const Unsupported = (
options: ConfigError.Options = { pathDelim: "." }
): ConfigError.ConfigError => {
const error = Object.create(proto)
error._tag = OpCodes.OP_UNSUPPORTED
error._op = OpCodes.OP_UNSUPPORTED
error.path = path
error.message = message
Object.defineProperty(error, "toString", {
Expand All @@ -135,26 +136,26 @@ export const Unsupported = (
export const isConfigError = (u: unknown): u is ConfigError.ConfigError => hasProperty(u, ConfigErrorTypeId)

/** @internal */
export const isAnd = (self: ConfigError.ConfigError): self is ConfigError.And => self._tag === OpCodes.OP_AND
export const isAnd = (self: ConfigError.ConfigError): self is ConfigError.And => self._op === OpCodes.OP_AND

/** @internal */
export const isOr = (self: ConfigError.ConfigError): self is ConfigError.Or => self._tag === OpCodes.OP_OR
export const isOr = (self: ConfigError.ConfigError): self is ConfigError.Or => self._op === OpCodes.OP_OR

/** @internal */
export const isInvalidData = (self: ConfigError.ConfigError): self is ConfigError.InvalidData =>
self._tag === OpCodes.OP_INVALID_DATA
self._op === OpCodes.OP_INVALID_DATA

/** @internal */
export const isMissingData = (self: ConfigError.ConfigError): self is ConfigError.MissingData =>
self._tag === OpCodes.OP_MISSING_DATA
self._op === OpCodes.OP_MISSING_DATA

/** @internal */
export const isSourceUnavailable = (self: ConfigError.ConfigError): self is ConfigError.SourceUnavailable =>
self._tag === OpCodes.OP_SOURCE_UNAVAILABLE
self._op === OpCodes.OP_SOURCE_UNAVAILABLE

/** @internal */
export const isUnsupported = (self: ConfigError.ConfigError): self is ConfigError.Unsupported =>
self._tag === OpCodes.OP_UNSUPPORTED
self._op === OpCodes.OP_UNSUPPORTED

/** @internal */
export const prefixed: {
Expand All @@ -164,7 +165,7 @@ export const prefixed: {
(prefix: ReadonlyArray<string>) => (self: ConfigError.ConfigError) => ConfigError.ConfigError,
(self: ConfigError.ConfigError, prefix: ReadonlyArray<string>) => ConfigError.ConfigError
>(2, (self, prefix) => {
switch (self._tag) {
switch (self._op) {
case OpCodes.OP_AND: {
return And(prefixed(self.left, prefix), prefixed(self.right, prefix))
}
Expand Down Expand Up @@ -201,12 +202,12 @@ type ConfigErrorCase = AndCase | OrCase

/** @internal */
interface AndCase {
readonly _tag: "AndCase"
readonly _op: "AndCase"
}

/** @internal */
interface OrCase {
readonly _tag: "OrCase"
readonly _op: "OrCase"
}

/** @internal */
Expand All @@ -218,17 +219,17 @@ export const reduceWithContext = dual<
const output: Array<Either.Either<Z, ConfigErrorCase>> = []
while (input.length > 0) {
const error = input.pop()!
switch (error._tag) {
switch (error._op) {
case OpCodes.OP_AND: {
input.push(error.right)
input.push(error.left)
output.push(Either.left({ _tag: "AndCase" }))
output.push(Either.left({ _op: "AndCase" }))
break
}
case OpCodes.OP_OR: {
input.push(error.right)
input.push(error.left)
output.push(Either.left({ _tag: "OrCase" }))
output.push(Either.left({ _op: "OrCase" }))
break
}
case OpCodes.OP_INVALID_DATA: {
Expand All @@ -252,9 +253,9 @@ export const reduceWithContext = dual<
const accumulator: Array<Z> = []
while (output.length > 0) {
const either = output.pop()!
switch (either._tag) {
switch (either._op) {
case "Left": {
switch (either.left._tag) {
switch (either.left._op) {
case "AndCase": {
const left = accumulator.pop()!
const right = accumulator.pop()!
Expand Down
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()
}
}
})

0 comments on commit ab02fbd

Please sign in to comment.