Skip to content

Instantly share code, notes, and snippets.

@otofu-square
Created September 21, 2017 06:54
Show Gist options
  • Save otofu-square/719b3dbbcbbcfbe8a0efaa6b8dfdc0ca to your computer and use it in GitHub Desktop.
Save otofu-square/719b3dbbcbbcfbe8a0efaa6b8dfdc0ca to your computer and use it in GitHub Desktop.
Throw error if predicate function returns true
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