Skip to content

Commit 770c6d0

Browse files
authored
Fix Effect.fn self transform binding (#7335)
1 parent ff98f0b commit 770c6d0

3 files changed

Lines changed: 21 additions & 1 deletion

File tree

.changeset/fix-effect-fn-self.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"effect": patch
3+
---
4+
5+
Fix `Effect.fn` binding the final transform as the generator body when using the `{ self }` overload.

packages/effect/src/internal/effect.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1257,7 +1257,7 @@ const makeFn = (
12571257
) => {
12581258
const body = typeof bodyOrOptions === "function"
12591259
? bodyOrOptions
1260-
: (pipeables.pop()!).bind(bodyOrOptions.self)
1260+
: (pipeables.shift()!).bind(bodyOrOptions.self)
12611261

12621262
return defineFunctionLength(body.length, function(this: any, ...args: Array<any>) {
12631263
let result = suspend(() => {

packages/effect/test/Effect.test.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3144,6 +3144,21 @@ describe("Effect", () => {
31443144
})
31453145
})
31463146

3147+
it.effect("should support self with pipeable arguments", () => {
3148+
const self = { prefix: "bound" }
3149+
const fn = Effect.fn(
3150+
{ self },
3151+
function*(this: typeof self, value: string) {
3152+
return `${this.prefix}:${value}`
3153+
},
3154+
Effect.map((value) => value.toUpperCase())
3155+
)
3156+
return Effect.gen(function*() {
3157+
const result = yield* fn("value")
3158+
assert.strictEqual(result, "BOUND:VALUE")
3159+
})
3160+
})
3161+
31473162
it("should proxy body length", () => {
31483163
const traced = Effect.fn(function*(a: string, b: number) {
31493164
return a.length + b

0 commit comments

Comments
 (0)