Created
September 21, 2017 06:54
-
-
Save otofu-square/719b3dbbcbbcfbe8a0efaa6b8dfdc0ca to your computer and use it in GitHub Desktop.
Throw error if predicate function returns true
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
import { curry } from "ramda"; | |
export const throwIf = curry( | |
(predicate: (_: any) => boolean, error: Error, value: any) => { | |
if (predicate(value)) { | |
throw error; | |
} else { | |
return value; | |
} | |
}, | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment