Skip to content

Commit 89b0c25

Browse files
evilj0etimdorr
authored andcommitted
Add support to compose only functions in utils/compose (reduxjs#2073)
* Add support to compose only functions in utils/compose * Remove some parens
1 parent 74d6477 commit 89b0c25

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

src/compose.js

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ export default function compose(...funcs) {
1414
return arg => arg
1515
}
1616

17+
funcs = funcs.filter(func => typeof func === 'function')
18+
1719
if (funcs.length === 1) {
1820
return funcs[0]
1921
}

test/compose.spec.js

+11
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,17 @@ describe('Utils', () => {
2121
expect(compose(c, a, b)(final)('')).toBe('cab')
2222
})
2323

24+
it('composes only functions', () => {
25+
const square = x => x * x
26+
const add = (x, y) => x + y
27+
28+
expect(compose(square, add, false)(1, 2)).toBe(9)
29+
expect(compose(square, add, undefined)(1, 2)).toBe(9)
30+
expect(compose(square, add, true)(1, 2)).toBe(9)
31+
expect(compose(square, add, NaN)(1, 2)).toBe(9)
32+
expect(compose(square, add, '42')(1, 2)).toBe(9)
33+
})
34+
2435
it('can be seeded with multiple arguments', () => {
2536
const square = x => x * x
2637
const add = (x, y) => x + y

0 commit comments

Comments
 (0)