I am working on a toy app to track job applications. I have this model:
type alias Application a =
{ company : String, date : String, applications : List a }
That is not working because List a should be List Applications but I cannot do recursive type alias.
I am trying to have a model that can 1) keep track of the updating application (onInput) 2) add the final updated application to a list of applications what would be the best data structure for that?
I was thinking something like {model, List model} should be the way to go, but I am not sure what is the elm way of doing that. Maybe I need 2 types? I tried but then I struggle having to pass 2 models to the update function (as the update function only can output 1 model).
I’m not sure whether I understood correctly, but here’s what I would do:
You want to handle applications. They contain the company and a date. So there’s this type that everything revolves around:
type alias Application =
{ company : String, date : String }
Then your app wants to curate a list of these, so:
type alias Model = List Application
Now, you also need to keep track of what the user has input so far for the company and for the date. This leaves you with:
type alias Model =
{ companyInput : String
, dateInput : String
, applications : List Application
}
I think you tried to reduce duplication of the strings, where there was none. They are two different things, actually! I know that sometimes this can be really hard to spot, so don’t worry. It happens to me all the time.
That was it! It worked. One thing that is happening now is that I have to click the “+” (add) button 2 times, does this have to do with the way coded the update function?
Also, for future reference I’ll be adding some comments to the code above for anybody who wants to play with a model that also includes a list of records.