mdgriffith / elm-codegen

https://package.elm-lang.org/packages/mdgriffith/elm-codegen/latest/
BSD 3-Clause "New" or "Revised" License
138 stars 16 forks source link

Deconstructing custom types without case..of #54

Open anmolitor opened 2 years ago

anmolitor commented 2 years ago

Hi Matthew,

thanks for the awesome package. It's so awesome in fact, that I'm trying to port my Elm Code generator travelm-agency to use this package under the hood instead of elm-syntax-dsl.

To hide the implementation details of the generated I18n type, I wrapped it in a constructor. Previously, I unpacked this in the arguments of the generated functions

someFunction :: I18n -> String
someFunction (I18n intl language) = ...

which does not seem to be possible with this package unless I'm missing something. This isn't mission critical, since I can generate a case..of expression matching on my custom type instead. I just think that unpacking custom types in arguments or let expressions would be nice. When unpacking multiple types, you get a nested case expression or you need to match on tuples (which are limited to 3 elements).

I'm not sure about the API since just naming arguments with Strings is very convenient.

Maybe just add a function in Elm.Let, since destructuring of tuples and records is already possible?

wolfadex commented 1 year ago

I'd love to expand this to tuples as well so that we don't need an additional case .. of or let .. in.