Skip to content

Commit

Permalink
fix(pipe): Special handling for 0-arg case. (#4936)
Browse files Browse the repository at this point in the history
* fix(pipe): Special handling for 0 args.

* test(pipe): Fix test label for 0-arg.

* fix(pipe): Remove check for missing args array.

The check is never reached in internal code, and is not exported for
external code. The behavior is not tested for, and arguably wrong.

* fix(pipe): no argument case run-time check

* refactor: revert checking for lack of array argument

Co-authored-by: Ben Lesh <ben@benlesh.com>
  • Loading branch information
leewz and benlesh committed Apr 3, 2020
1 parent f39eb29 commit 2e9d867
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion spec/util/pipe-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ describe('pipe', () => {
expect(c).to.equal(a);
});

it('should return a noop if not passed a function', () => {
it('should return the identity if not passed any functions', () => {
const c = pipe();

expect(c('whatever')).to.equal('whatever');
Expand Down
5 changes: 3 additions & 2 deletions src/internal/util/pipe.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { noop } from './noop';
import { identity } from './identity';
import { UnaryFunction } from '../types';

/* tslint:disable:max-line-length */
Expand All @@ -21,8 +22,8 @@ export function pipe(...fns: Array<UnaryFunction<any, any>>): UnaryFunction<any,

/** @internal */
export function pipeFromArray<T, R>(fns: Array<UnaryFunction<T, R>>): UnaryFunction<T, R> {
if (!fns) {
return noop as UnaryFunction<any, any>;
if (fns.length === 0) {
return identity as UnaryFunction<any, any>;
}

if (fns.length === 1) {
Expand Down

0 comments on commit 2e9d867

Please sign in to comment.