Bidirectional converter for
sum types. For example, given the
data type:
data Example
= Foo Int
| Bar Bool Int
the TOML codec will look like
matchFoo :: Example -> Maybe Int
matchFoo (Foo num) = Just num
matchFoo _ = Nothing
matchBar :: Example -> Maybe (Bool, Int)
matchBar (Bar b num) = Just (b, num)
matchBar _ = Nothing
barCodec :: TomlCodec (Bool, Int)
barCodec = Toml.pair
(Toml.bool "a")
(Toml.int "b")
exampleCodec :: TomlCodec Example
exampleCodec =
dimatch matchFoo Foo (Toml.int "foo")
<|> dimatch matchBar (uncurry Bar) (Toml.table barCodec "bar")