recover<U>(getFallback: Object): Object
Allows to never fail from parsing an input by providing a lazy fallback.
getFallback: Object
fallback for usage without callback
import { x } from 'unhoax'import pipe from 'just-pipe' // or from elsewhereconst schema = pipe(x.number, x.recover(() => 'not a number'))schema.parse(42) // { success: true, value: 42 }schema.parse('toto') // { success: true, value: 'not a number' } Copy
import { x } from 'unhoax'import pipe from 'just-pipe' // or from elsewhereconst schema = pipe(x.number, x.recover(() => 'not a number'))schema.parse(42) // { success: true, value: 42 }schema.parse('toto') // { success: true, value: 'not a number' }
import { x } from 'unhoax'const recoverFromNaN = x.recover(() => 'not a number')const schema = recoverFromNaN(x.number) Copy
import { x } from 'unhoax'const recoverFromNaN = x.recover(() => 'not a number')const schema = recoverFromNaN(x.number)
Allows to never fail from parsing an input by providing a lazy fallback.