Skip to content

Commit

Permalink
fix: tap and andThen fallthrough function (#2264)
Browse files Browse the repository at this point in the history
patroza authored Mar 8, 2024

Verified

This commit was signed with the committer’s verified signature.
1 parent fa9663c commit e03811e
Showing 7 changed files with 31 additions and 17 deletions.
5 changes: 5 additions & 0 deletions .changeset/angry-shirts-repair.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"effect": patch
---

fix: unmatched function fallthrough in `andThen` and `tap`
10 changes: 5 additions & 5 deletions packages/effect/src/Effect.ts
Original file line number Diff line number Diff line change
@@ -54,7 +54,7 @@ import * as Scheduler from "./Scheduler.js"
import type * as Scope from "./Scope.js"
import type * as Supervisor from "./Supervisor.js"
import type * as Tracer from "./Tracer.js"
import type { Concurrency, Covariant, MergeRecord, NoInfer } from "./Types.js"
import type { Concurrency, Covariant, MergeRecord, NoInfer, NotFunction } from "./Types.js"
import type * as Unify from "./Unify.js"

// -------------------------------------------------------------------------------------
@@ -3557,7 +3557,7 @@ export const andThen: {
: [X] extends [Promise<infer A1>] ? Effect<A1, E | Cause.UnknownException, R>
: Effect<X, E, R>
<X>(
f: X
f: NotFunction<X>
): <A, E, R>(
self: Effect<A, E, R>
) => [X] extends [Effect<infer A1, infer E1, infer R1>] ? Effect<A1, E | E1, R | R1>
@@ -3571,7 +3571,7 @@ export const andThen: {
: Effect<X, E, R>
<A, E, R, X>(
self: Effect<A, E, R>,
f: X
f: NotFunction<X>
): [X] extends [Effect<infer A1, infer E1, infer R1>] ? Effect<A1, E | E1, R | R1>
: [X] extends [Promise<infer A1>] ? Effect<A1, E | Cause.UnknownException, R>
: Effect<X, E, R>
@@ -3686,7 +3686,7 @@ export const tap: {
: [X] extends [Promise<infer _A1>] ? Effect<A, E | Cause.UnknownException, R>
: Effect<A, E, R>
<X>(
f: X
f: NotFunction<X>
): <A, E, R>(
self: Effect<A, E, R>
) => [X] extends [Effect<infer _A1, infer E1, infer R1>] ? Effect<A, E | E1, R | R1>
@@ -3700,7 +3700,7 @@ export const tap: {
: Effect<A, E, R>
<A, E, R, X>(
self: Effect<A, E, R>,
f: X
f: NotFunction<X>
): [X] extends [Effect<infer _A1, infer E1, infer R1>] ? Effect<A, E | E1, R | R1>
: [X] extends [Promise<infer _A1>] ? Effect<A, E | Cause.UnknownException, R>
: Effect<A, E, R>
6 changes: 3 additions & 3 deletions packages/effect/src/Either.ts
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@ import type { Option } from "./Option.js"
import type { Pipeable } from "./Pipeable.js"
import type { Predicate, Refinement } from "./Predicate.js"
import { isFunction } from "./Predicate.js"
import type { Covariant, MergeRecord, NoInfer } from "./Types.js"
import type { Covariant, MergeRecord, NoInfer, NotFunction } from "./Types.js"
import type * as Unify from "./Unify.js"
import * as Gen from "./Utils.js"

@@ -587,11 +587,11 @@ export const andThen: {
<R, R2, L2>(f: (right: R) => Either<R2, L2>): <L>(self: Either<R, L>) => Either<R2, L | L2>
<R2, L2>(f: Either<R2, L2>): <L, R1>(self: Either<R1, L>) => Either<R2, L | L2>
<R, R2>(f: (right: R) => R2): <L>(self: Either<R, L>) => Either<R2, L>
<R2>(right: R2): <R1, L>(self: Either<R1, L>) => Either<R2, L>
<R2>(right: NotFunction<R2>): <R1, L>(self: Either<R1, L>) => Either<R2, L>
<R, L, R2, L2>(self: Either<R, L>, f: (right: R) => Either<R2, L2>): Either<R2, L | L2>
<R, L, R2, L2>(self: Either<R, L>, f: Either<R2, L2>): Either<R2, L | L2>
<R, L, R2>(self: Either<R, L>, f: (right: R) => R2): Either<R2, L>
<R, L, R2>(self: Either<R, L>, f: R2): Either<R2, L>
<R, L, R2>(self: Either<R, L>, f: NotFunction<R2>): Either<R2, L>
} = dual(
2,
<R, L, R2, L2>(self: Either<R, L>, f: (right: R) => Either<R2, L2> | Either<R2, L2>): Either<R2, L | L2> =>
6 changes: 3 additions & 3 deletions packages/effect/src/Option.ts
Original file line number Diff line number Diff line change
@@ -14,7 +14,7 @@ import type { Order } from "./Order.js"
import * as order from "./Order.js"
import type { Pipeable } from "./Pipeable.js"
import type { Predicate, Refinement } from "./Predicate.js"
import type { Covariant, NoInfer } from "./Types.js"
import type { Covariant, NoInfer, NotFunction } from "./Types.js"
import type * as Unify from "./Unify.js"
import * as Gen from "./Utils.js"

@@ -660,11 +660,11 @@ export const andThen: {
<A, B>(f: (a: A) => Option<B>): (self: Option<A>) => Option<B>
<B>(f: Option<B>): <A>(self: Option<A>) => Option<B>
<A, B>(f: (a: A) => B): (self: Option<A>) => Option<B>
<B>(f: B): <A>(self: Option<A>) => Option<B>
<B>(f: NotFunction<B>): <A>(self: Option<A>) => Option<B>
<A, B>(self: Option<A>, f: (a: A) => Option<B>): Option<B>
<A, B>(self: Option<A>, f: Option<B>): Option<B>
<A, B>(self: Option<A>, f: (a: A) => B): Option<B>
<A, B>(self: Option<A>, f: B): Option<B>
<A, B>(self: Option<A>, f: NotFunction<B>): Option<B>
} = dual(
2,
<A, B>(self: Option<A>, f: (a: A) => Option<B> | Option<B>): Option<B> =>
5 changes: 5 additions & 0 deletions packages/effect/src/Types.ts
Original file line number Diff line number Diff line change
@@ -190,3 +190,8 @@ export type Contravariant<A> = (_: A) => void
* @since 2.0.0
*/
export type MatchRecord<S, onTrue, onFalse> = {} extends S ? onTrue : onFalse

/**
* @since 2.0.0
*/
export type NotFunction<T> = T extends Function ? never : T
10 changes: 5 additions & 5 deletions packages/effect/src/internal/core.ts
Original file line number Diff line number Diff line change
@@ -35,7 +35,7 @@ import type * as RuntimeFlags from "../RuntimeFlags.js"
import * as RuntimeFlagsPatch from "../RuntimeFlagsPatch.js"
import type * as Scope from "../Scope.js"
import type * as Tracer from "../Tracer.js"
import type { NoInfer } from "../Types.js"
import type { NoInfer, NotFunction } from "../Types.js"
import * as _blockedRequests from "./blockedRequests.js"
import * as internalCause from "./cause.js"
import * as deferred from "./deferred.js"
@@ -697,7 +697,7 @@ export const andThen: {
: [X] extends [Promise<infer A1>] ? Effect.Effect<A1, E | Cause.UnknownException, R>
: Effect.Effect<X, E, R>
<X>(
f: X
f: NotFunction<X>
): <A, E, R>(
self: Effect.Effect<A, E, R>
) => [X] extends [Effect.Effect<infer A1, infer E1, infer R1>] ? Effect.Effect<A1, E | E1, R | R1>
@@ -711,7 +711,7 @@ export const andThen: {
: Effect.Effect<X, E, R>
<A, E, R, X>(
self: Effect.Effect<A, E, R>,
f: X
f: NotFunction<X>
): [X] extends [Effect.Effect<infer A1, infer E1, infer R1>] ? Effect.Effect<A1, E | E1, R | R1>
: [X] extends [Promise<infer A1>] ? Effect.Effect<A1, E | Cause.UnknownException, R>
: Effect.Effect<X, E, R>
@@ -1169,7 +1169,7 @@ export const tap = dual<
: [X] extends [Promise<infer _A1>] ? Effect.Effect<A, E | Cause.UnknownException, R>
: Effect.Effect<A, E, R>
<X>(
f: X
f: NotFunction<X>
): <A, E, R>(
self: Effect.Effect<A, E, R>
) => [X] extends [Effect.Effect<infer _A1, infer E1, infer R1>] ? Effect.Effect<A, E | E1, R | R1>
@@ -1185,7 +1185,7 @@ export const tap = dual<
: Effect.Effect<A, E, R>
<A, E, R, X>(
self: Effect.Effect<A, E, R>,
f: X
f: NotFunction<X>
): [X] extends [Effect.Effect<infer _A1, infer E1, infer R1>] ? Effect.Effect<A, E | E1, R | R1>
: [X] extends [Promise<infer _A1>] ? Effect.Effect<A, E | Cause.UnknownException, R>
: Effect.Effect<A, E, R>
6 changes: 5 additions & 1 deletion packages/platform/src/internal/worker.ts
Original file line number Diff line number Diff line change
@@ -405,7 +405,11 @@ export const makePoolSerialized = <I extends Schema.TaggedRequest.Any>(
makeSerialized<I>(options),
Effect.tap((worker) => Effect.sync(() => workers.add(worker))),
Effect.tap((worker) => Effect.addFinalizer(() => Effect.sync(() => workers.delete(worker)))),
options.onCreate ? Effect.tap(options.onCreate) : identity,
options.onCreate
? Effect.tap(
options.onCreate as (worker: Worker.SerializedWorker<I>) => Effect.Effect<void, WorkerError>
)
: identity,
Effect.provideService(WorkerManager, manager)
)
const backing = yield* _(

0 comments on commit e03811e

Please sign in to comment.