Skip to content

Commit

Permalink
Auto merge of #78 - DockYard:fix-pipe-helper, r=poteto
Browse files Browse the repository at this point in the history
Fix return value passing in `pipe` helper

For #73
  • Loading branch information
homu committed Feb 23, 2016
2 parents 74a36ad + 72342b1 commit 3ea3e31
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 3ea3e31

Please sign in to comment.