Skip to content

Commit

Permalink
Fix return value passing in pipe helper
Browse files Browse the repository at this point in the history
  • Loading branch information
poteto committed Feb 23, 2016
1 parent f3348ee commit 72342b1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion addon/helpers/pipe.js
Expand Up @@ -12,7 +12,7 @@ export function pipe(actions = []) {
return curr(...args);
}

return curr(acc, ...args);
return curr(acc);
}, undefined);
};
}
Expand Down
13 changes: 13 additions & 0 deletions tests/unit/helpers/pipe-test.js
Expand Up @@ -11,9 +11,22 @@ function square(x) {
return x * x;
}

function subtract(x, y) {
if (typeof y === 'undefined') {
throw new Error('2nd argument is undefined');
}
return x - y;
}

test('it pipes functions together', function(assert) {
let piped = pipe([add, square, Math.sqrt]);
let result = piped(2, 4);

assert.equal(result, 6, 'it pipes functions together');
});

test('first function is variadic, rest are unary', function(assert) {
let piped = pipe([add, square, Math.sqrt, subtract]);

assert.throws(() => piped(2, 4), 'should throw an error');
});

0 comments on commit 72342b1

Please sign in to comment.