-
-
Notifications
You must be signed in to change notification settings - Fork 281
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Preserve function
length
property in Effect.fn
/ `Effect.fnUntrac… (
- Loading branch information
Showing
4 changed files
with
99 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
--- | ||
"effect": patch | ||
--- | ||
|
||
Preserve function `length` property in `Effect.fn` / `Effect.fnUntraced`, closes #4435 | ||
|
||
Previously, functions created with `Effect.fn` and `Effect.fnUntraced` always had a `.length` of `0`, regardless of their actual number of parameters. This has been fixed so that the `length` property correctly reflects the expected number of arguments. | ||
|
||
**Before** | ||
|
||
```ts | ||
import { Effect } from "effect" | ||
|
||
const fn1 = Effect.fn("fn1")(function* (n: number) { | ||
return n | ||
}) | ||
|
||
console.log(fn1.length) | ||
// Output: 0 ❌ (incorrect) | ||
|
||
const fn2 = Effect.fnUntraced(function* (n: number) { | ||
return n | ||
}) | ||
|
||
console.log(fn2.length) | ||
// Output: 0 ❌ (incorrect) | ||
``` | ||
|
||
**After** | ||
|
||
```ts | ||
import { Effect } from "effect" | ||
|
||
const fn1 = Effect.fn("fn1")(function* (n: number) { | ||
return n | ||
}) | ||
|
||
console.log(fn1.length) | ||
// Output: 1 ✅ (correct) | ||
|
||
const fn2 = Effect.fnUntraced(function* (n: number) { | ||
return n | ||
}) | ||
|
||
console.log(fn2.length) | ||
// Output: 1 ✅ (correct) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters