Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove filtering inside compose #2167

Merged
merged 1 commit into from
Dec 30, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions src/compose.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
*/

export default function compose(...funcs) {
funcs = funcs.filter(func => typeof func === 'function')

if (funcs.length === 0) {
return arg => arg
}
Expand Down
15 changes: 7 additions & 8 deletions test/compose.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ describe('Utils', () => {
expect(compose(c, a, b)(final)('')).toBe('cab')
})

it('composes only functions', () => {
it('throws at runtime if argument is not a function', () => {
const square = x => x * x
const add = (x, y) => x + y
expect(compose(square, add, false)(1, 2)).toBe(9)
expect(compose(square, add, undefined)(1, 2)).toBe(9)
expect(compose(square, add, true)(1, 2)).toBe(9)
expect(compose(square, add, NaN)(1, 2)).toBe(9)
expect(compose(square, add, '42')(1, 2)).toBe(9)

expect(() => compose(square, add, false)(1, 2)).toThrow()
expect(() => compose(square, add, undefined)(1, 2)).toThrow()
expect(() => compose(square, add, true)(1, 2)).toThrow()
expect(() => compose(square, add, NaN)(1, 2)).toThrow()
expect(() => compose(square, add, '42')(1, 2)).toThrow()
})

it('can be seeded with multiple arguments', () => {
Expand All @@ -41,7 +41,6 @@ describe('Utils', () => {
it('returns the first given argument if given no functions', () => {
expect(compose()(1, 2)).toBe(1)
expect(compose()(3)).toBe(3)
expect(compose(false,4,'test')(3)).toBe(3)
expect(compose()()).toBe(undefined)
})

Expand Down