I like the look and feel of it! I threw a bunch of types at the decoder generator to see what it could handle
. I’m impressed
!
It handles:
-
Records -
Tuples -
Dicts -
Lists -
Nested structures like a list of tuples -
Sum types (e.g. type Color = Red | Green | Blue)
I’ve noticed is struggles with product types like type Email = Email String. If I were writing this by hand I’d implement the decoder as this one-liner:
decodeEmail =
Dec.map Email Dec.string
but the generator attempts to decode it using a huge nested case and multiple calls to decodeValue 
decodeEmail =
let
recover xs =
case xs of
a0::bs->
case decodeValue Dec.string a0 of
Ok "Email"->
case bs of
a1::cs ->
case decodeValue Dec.string a1 of
Ok a1_->
Dec.succeed <| Email a1_
Err err->
Dec.fail err
_->
Dec.fail <| "Invalid fields for constructor Email: " ++ toString bs
Ok other->
Dec.fail <| "Invalid constructor field found: " ++ other
Err err->
Dec.fail err
_->
Dec.fail "Invalid JSON input: empty list"
in
Dec.list Dec.value |> andThen recover