nullable

inline fun <I : Any, O : Any> nullable(name: String, crossinline encoder: (I) -> O, crossinline decoder: (O) -> I?): Codec<I, O>(source)

Builds a codec around a decoder that reports failure by returning null.

Parameters

I

domain type to decode and encode.

O

serialized representation produced during encoding.

name

human readable identifier included in decode errors.

encoder

transformation applied when encoding I to O.

decoder

transformation that converts O back to I; returning null marks the input invalid.