Created
July 20, 2017 11:23
-
-
Save Kamisama666/240962eb61a12d1ecdedd9d0331af8dc to your computer and use it in GitHub Desktop.
Composable function that checks if an object has a key, throws an error if not
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
const fn = require('fn.js'); | |
const has = fn.curry(function(key, object) { | |
if (!object[key]) { | |
throw new Error(`Missing key '${key}' on object`); | |
} | |
return object; | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment