UNPKG

ts-cast

Version:
13 lines (12 loc) 412 B
import { withName } from '../helpers/names'; import { throwTypeError } from './throw-type-error'; const either = (caster, leftFactory, rightFactory) => withName((value, context) => { try { const casted = caster(value, context, throwTypeError); return rightFactory(casted); } catch (err) { return leftFactory(err); } }, `either<*, ${caster.name}>`); export default either;