Skip to content

Commit e03811e

Browse files
authoredMar 8, 2024··
fix: tap and andThen fallthrough function (#2264)
1 parent fa9663c commit e03811e

File tree

7 files changed

+31
-17
lines changed

7 files changed

+31
-17
lines changed
 

‎.changeset/angry-shirts-repair.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"effect": patch
3+
---
4+
5+
fix: unmatched function fallthrough in `andThen` and `tap`

‎packages/effect/src/Effect.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ import * as Scheduler from "./Scheduler.js"
5454
import type * as Scope from "./Scope.js"
5555
import type * as Supervisor from "./Supervisor.js"
5656
import type * as Tracer from "./Tracer.js"
57-
import type { Concurrency, Covariant, MergeRecord, NoInfer } from "./Types.js"
57+
import type { Concurrency, Covariant, MergeRecord, NoInfer, NotFunction } from "./Types.js"
5858
import type * as Unify from "./Unify.js"
5959

6060
// -------------------------------------------------------------------------------------
@@ -3557,7 +3557,7 @@ export const andThen: {
35573557
: [X] extends [Promise<infer A1>] ? Effect<A1, E | Cause.UnknownException, R>
35583558
: Effect<X, E, R>
35593559
<X>(
3560-
f: X
3560+
f: NotFunction<X>
35613561
): <A, E, R>(
35623562
self: Effect<A, E, R>
35633563
) => [X] extends [Effect<infer A1, infer E1, infer R1>] ? Effect<A1, E | E1, R | R1>
@@ -3571,7 +3571,7 @@ export const andThen: {
35713571
: Effect<X, E, R>
35723572
<A, E, R, X>(
35733573
self: Effect<A, E, R>,
3574-
f: X
3574+
f: NotFunction<X>
35753575
): [X] extends [Effect<infer A1, infer E1, infer R1>] ? Effect<A1, E | E1, R | R1>
35763576
: [X] extends [Promise<infer A1>] ? Effect<A1, E | Cause.UnknownException, R>
35773577
: Effect<X, E, R>
@@ -3686,7 +3686,7 @@ export const tap: {
36863686
: [X] extends [Promise<infer _A1>] ? Effect<A, E | Cause.UnknownException, R>
36873687
: Effect<A, E, R>
36883688
<X>(
3689-
f: X
3689+
f: NotFunction<X>
36903690
): <A, E, R>(
36913691
self: Effect<A, E, R>
36923692
) => [X] extends [Effect<infer _A1, infer E1, infer R1>] ? Effect<A, E | E1, R | R1>
@@ -3700,7 +3700,7 @@ export const tap: {
37003700
: Effect<A, E, R>
37013701
<A, E, R, X>(
37023702
self: Effect<A, E, R>,
3703-
f: X
3703+
f: NotFunction<X>
37043704
): [X] extends [Effect<infer _A1, infer E1, infer R1>] ? Effect<A, E | E1, R | R1>
37053705
: [X] extends [Promise<infer _A1>] ? Effect<A, E | Cause.UnknownException, R>
37063706
: Effect<A, E, R>

‎packages/effect/src/Either.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import type { Option } from "./Option.js"
1212
import type { Pipeable } from "./Pipeable.js"
1313
import type { Predicate, Refinement } from "./Predicate.js"
1414
import { isFunction } from "./Predicate.js"
15-
import type { Covariant, MergeRecord, NoInfer } from "./Types.js"
15+
import type { Covariant, MergeRecord, NoInfer, NotFunction } from "./Types.js"
1616
import type * as Unify from "./Unify.js"
1717
import * as Gen from "./Utils.js"
1818

@@ -587,11 +587,11 @@ export const andThen: {
587587
<R, R2, L2>(f: (right: R) => Either<R2, L2>): <L>(self: Either<R, L>) => Either<R2, L | L2>
588588
<R2, L2>(f: Either<R2, L2>): <L, R1>(self: Either<R1, L>) => Either<R2, L | L2>
589589
<R, R2>(f: (right: R) => R2): <L>(self: Either<R, L>) => Either<R2, L>
590-
<R2>(right: R2): <R1, L>(self: Either<R1, L>) => Either<R2, L>
590+
<R2>(right: NotFunction<R2>): <R1, L>(self: Either<R1, L>) => Either<R2, L>
591591
<R, L, R2, L2>(self: Either<R, L>, f: (right: R) => Either<R2, L2>): Either<R2, L | L2>
592592
<R, L, R2, L2>(self: Either<R, L>, f: Either<R2, L2>): Either<R2, L | L2>
593593
<R, L, R2>(self: Either<R, L>, f: (right: R) => R2): Either<R2, L>
594-
<R, L, R2>(self: Either<R, L>, f: R2): Either<R2, L>
594+
<R, L, R2>(self: Either<R, L>, f: NotFunction<R2>): Either<R2, L>
595595
} = dual(
596596
2,
597597
<R, L, R2, L2>(self: Either<R, L>, f: (right: R) => Either<R2, L2> | Either<R2, L2>): Either<R2, L | L2> =>

‎packages/effect/src/Option.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import type { Order } from "./Order.js"
1414
import * as order from "./Order.js"
1515
import type { Pipeable } from "./Pipeable.js"
1616
import type { Predicate, Refinement } from "./Predicate.js"
17-
import type { Covariant, NoInfer } from "./Types.js"
17+
import type { Covariant, NoInfer, NotFunction } from "./Types.js"
1818
import type * as Unify from "./Unify.js"
1919
import * as Gen from "./Utils.js"
2020

@@ -660,11 +660,11 @@ export const andThen: {
660660
<A, B>(f: (a: A) => Option<B>): (self: Option<A>) => Option<B>
661661
<B>(f: Option<B>): <A>(self: Option<A>) => Option<B>
662662
<A, B>(f: (a: A) => B): (self: Option<A>) => Option<B>
663-
<B>(f: B): <A>(self: Option<A>) => Option<B>
663+
<B>(f: NotFunction<B>): <A>(self: Option<A>) => Option<B>
664664
<A, B>(self: Option<A>, f: (a: A) => Option<B>): Option<B>
665665
<A, B>(self: Option<A>, f: Option<B>): Option<B>
666666
<A, B>(self: Option<A>, f: (a: A) => B): Option<B>
667-
<A, B>(self: Option<A>, f: B): Option<B>
667+
<A, B>(self: Option<A>, f: NotFunction<B>): Option<B>
668668
} = dual(
669669
2,
670670
<A, B>(self: Option<A>, f: (a: A) => Option<B> | Option<B>): Option<B> =>

‎packages/effect/src/Types.ts

+5
Original file line numberDiff line numberDiff line change
@@ -190,3 +190,8 @@ export type Contravariant<A> = (_: A) => void
190190
* @since 2.0.0
191191
*/
192192
export type MatchRecord<S, onTrue, onFalse> = {} extends S ? onTrue : onFalse
193+
194+
/**
195+
* @since 2.0.0
196+
*/
197+
export type NotFunction<T> = T extends Function ? never : T

‎packages/effect/src/internal/core.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import type * as RuntimeFlags from "../RuntimeFlags.js"
3535
import * as RuntimeFlagsPatch from "../RuntimeFlagsPatch.js"
3636
import type * as Scope from "../Scope.js"
3737
import type * as Tracer from "../Tracer.js"
38-
import type { NoInfer } from "../Types.js"
38+
import type { NoInfer, NotFunction } from "../Types.js"
3939
import * as _blockedRequests from "./blockedRequests.js"
4040
import * as internalCause from "./cause.js"
4141
import * as deferred from "./deferred.js"
@@ -697,7 +697,7 @@ export const andThen: {
697697
: [X] extends [Promise<infer A1>] ? Effect.Effect<A1, E | Cause.UnknownException, R>
698698
: Effect.Effect<X, E, R>
699699
<X>(
700-
f: X
700+
f: NotFunction<X>
701701
): <A, E, R>(
702702
self: Effect.Effect<A, E, R>
703703
) => [X] extends [Effect.Effect<infer A1, infer E1, infer R1>] ? Effect.Effect<A1, E | E1, R | R1>
@@ -711,7 +711,7 @@ export const andThen: {
711711
: Effect.Effect<X, E, R>
712712
<A, E, R, X>(
713713
self: Effect.Effect<A, E, R>,
714-
f: X
714+
f: NotFunction<X>
715715
): [X] extends [Effect.Effect<infer A1, infer E1, infer R1>] ? Effect.Effect<A1, E | E1, R | R1>
716716
: [X] extends [Promise<infer A1>] ? Effect.Effect<A1, E | Cause.UnknownException, R>
717717
: Effect.Effect<X, E, R>
@@ -1169,7 +1169,7 @@ export const tap = dual<
11691169
: [X] extends [Promise<infer _A1>] ? Effect.Effect<A, E | Cause.UnknownException, R>
11701170
: Effect.Effect<A, E, R>
11711171
<X>(
1172-
f: X
1172+
f: NotFunction<X>
11731173
): <A, E, R>(
11741174
self: Effect.Effect<A, E, R>
11751175
) => [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<
11851185
: Effect.Effect<A, E, R>
11861186
<A, E, R, X>(
11871187
self: Effect.Effect<A, E, R>,
1188-
f: X
1188+
f: NotFunction<X>
11891189
): [X] extends [Effect.Effect<infer _A1, infer E1, infer R1>] ? Effect.Effect<A, E | E1, R | R1>
11901190
: [X] extends [Promise<infer _A1>] ? Effect.Effect<A, E | Cause.UnknownException, R>
11911191
: Effect.Effect<A, E, R>

‎packages/platform/src/internal/worker.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,11 @@ export const makePoolSerialized = <I extends Schema.TaggedRequest.Any>(
405405
makeSerialized<I>(options),
406406
Effect.tap((worker) => Effect.sync(() => workers.add(worker))),
407407
Effect.tap((worker) => Effect.addFinalizer(() => Effect.sync(() => workers.delete(worker)))),
408-
options.onCreate ? Effect.tap(options.onCreate) : identity,
408+
options.onCreate
409+
? Effect.tap(
410+
options.onCreate as (worker: Worker.SerializedWorker<I>) => Effect.Effect<void, WorkerError>
411+
)
412+
: identity,
409413
Effect.provideService(WorkerManager, manager)
410414
)
411415
const backing = yield* _(

0 commit comments

Comments
 (0)
Please sign in to comment.