• If the decoder fails, the given value is returned instead.

    Type Parameters

    • T

    Parameters

    Returns Decoder<T>

    Example

    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

    Remarks

    This is implemented by using Decode.oneOf:

    function optional(value, child) {
    return Decode.oneOf([ child, Decode.succeed(value) ]);
    }

Generated using TypeDoc