UNPKG

crocks

Version:

A collection of well known Algebraic Datatypes for your utter enjoyment.

26 lines (19 loc) 613 B
/** @license ISC License (c) copyright 2017 original and current authors */ /** @author Ian Hofmann-Hicks (evil) */ var ref = require('.'); var Err = ref.Err; var Ok = ref.Ok; var curry = require('../core/curry') var isFunction = require('../core/isFunction') function tryCatch(fn) { if(!isFunction(fn)) { throw new TypeError('tryCatch: Function required for first argument') } var safe = function() { try { return Ok(fn.apply(this, arguments)) } catch(e) { return Err(e) } } Object.defineProperty(safe, 'length', { value: fn.length }) return safe } module.exports = curry(tryCatch)