Skip to content

Commit

Permalink
fix: fail fast with descriptive error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
emilianobovetti committed Dec 5, 2019
1 parent 598bf98 commit 5aa5b1a
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/curry.js
@@ -1,9 +1,9 @@
import { isInteger } from '@fpc/types';
import { isInteger, expectFunction } from '@fpc/types';
import { curry as unsafeCurry } from './internals';
import { failWith } from './failWith';

export const curry = (fn, numArgs = fn.length) => (
isInteger(numArgs) && numArgs > 0
? unsafeCurry(fn, numArgs)
? unsafeCurry(expectFunction(fn), numArgs)
: failWith(new TypeError(`Expected positive integer, got ${numArgs}`))
);
7 changes: 6 additions & 1 deletion src/flip.js
@@ -1 +1,6 @@
export const flip = fn => (...args) => fn(...args.reverse());
import { expectFunction } from '@fpc/types';

export const flip = fn => (
/* eslint-disable no-sequences */
expectFunction(fn), (...args) => fn(...args.reverse())
);
4 changes: 4 additions & 0 deletions src/lazy.js
@@ -1,6 +1,10 @@
import { expectFunction } from '@fpc/types';

const empty = {};

export const lazy = (fn, ...args) => {
expectFunction(fn);

let result = empty;

const cached = () => (
Expand Down
7 changes: 6 additions & 1 deletion src/negate.js
@@ -1 +1,6 @@
export const negate = fn => (...args) => !fn(...args);
import { expectFunction } from '@fpc/types';

export const negate = fn => (
/* eslint-disable no-sequences */
expectFunction(fn), (...args) => !fn(...args)
);

0 comments on commit 5aa5b1a

Please sign in to comment.