const decoder = Decode.optional(42, Decode.number);
decode(decoder, 100) === 100
decode(decoder, -10) === -10
decode(decoder, '3') === 42
decode(decoder, NaN) === 42
decode(decoder, null) === 42
This is implemented by using Decode.oneOf:
function optional(value, child) {
return Decode.oneOf([ child, Decode.succeed(value) ]);
}
Generated using TypeDoc
If the decoder fails, the given value is returned instead.