Skip to content

Commit e5e779a

Browse files
Expose a length property for curried functions (#477)
Co-authored-by: Dale Francis <[email protected]>
1 parent ce8f939 commit e5e779a

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

src/core/curry.js

+6
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@ function curry(fn) {
4343
value: true
4444
})
4545

46+
Object.defineProperty(curried, 'length', {
47+
enumerable: false,
48+
writable: false,
49+
value: fn.length
50+
})
51+
4652
return curried
4753
}
4854

src/core/curry.spec.js

+8
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,11 @@ test('curry on a curried function', t => {
7878

7979
t.end()
8080
})
81+
82+
test('curried function with arity exposed', t => {
83+
const fn = (a, b) => a + b
84+
const curried = curry(fn)
85+
t.equal(curried.length, fn.length, 'returns the same arity as its uncurried counterpart')
86+
87+
t.end()
88+
})

0 commit comments

Comments
 (0)