Decoder generator and imports cleanup tool

I like the look and feel of it! I threw a bunch of types at the decoder generator to see what it could handle :laughing:. I’m impressed :100: !

It handles:

  • :white_check_mark: Records
  • :white_check_mark: Tuples
  • :white_check_mark: Dicts
  • :white_check_mark: Lists
  • :white_check_mark: Nested structures like a list of tuples
  • :white_check_mark: 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 :cold_sweat:

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