Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: fail fast with descriptive error messages
- Loading branch information
1 parent
598bf98
commit 5aa5b1a
Showing
4 changed files
with
18 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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}`)) | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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()) | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
); |