@eluvio/elv-js-helpers
Version:
A collection of Javascript helper functions used by several Eluvio libraries.
24 lines (20 loc) • 452 B
JavaScript
const Err = require('../ADT/Err')
const Ok = require('../ADT/Ok')
const curry = require('../Functional/curry')
// validates that checkFn(value) is true
// returns Result
const validateWithFn = curry(
(checkFn, errorMsgOrObj, value) => {
try {
if(checkFn){
return Ok(value)
} else {
return Err([errorMsgOrObj])
}
} catch (e) {
return Err([e])
}
}
)
module.exports = validateWithFn