Updating nested records in Elm
Wouter In t Velt

In certain cases it makes sense to do something like this:

case msg of
Rated newRating ->
movie = model.currentMovie
{ model | currentMovie = Movie model.title model.director newRating}

I’ve found this pattern useful in cases like updating the entire record, e.g.:

type alias User = { name : String, isLoggedIn : Bool }
case msg of
UpdateCurrentUser newUser ->
{ model | user = User newUser.name True }

Still not ideal, but I found it to help me reduce some code in the app I’m currently working on :-)

Show your support

Clapping shows how much you appreciated rainteller’s story.