here is data model , the goal is easy, just to view the type Gift in the HTML and user can use a dropdown list to update field type_ of Gift. But the question is how to build dropdown list from a custom type ?
type Fruit
= Apple
| Banana
| Orange
type alias Gift =
{ quantity : int
type_ : Fruit
}
I tried to add a update/view operation on view
how to convert the type Fruit to String ? There are two possible workarounds:
Building a dict, which mays
FruittoString{Apple:"Apple",Banana,"Banana"}I don't think this will work since key in
Dictneeds to beComparable,but how to implement ordering incustom type? there was an issue but there seems no solution yet (https://github.com/elm/compiler/issues/774)Using
Enum/makeEnummodule this will bring more code and easily can break.fruitTypeEnum = Enum.makeEnum [Apple, Banana, Orange ] -- in view (List.map (\x -> Enum.toString fruitTypeEnum x) [Apple,Banana,Orange])this has to maintain
apple,banana,orangelist in three places ( including the declaration )
Thank you for your time reading this .Appreciate any help:)