Agreed! I wrote my comment because you also give a “better solution”.
Berry Groenendijk
11

Hmm, still not sure I fully understand. If you want to display the new username in the actual message, both “better solutions” allow that, like this.

The recursive solution does of course require a separate branch for the InfoMessage value. Which may be useful if you want to have other message types as well.

-- better: recursive call to update
update : Msg -> Model -> (Model, Cmd Msg)
update msg model =
case msg of
...
LoginSucceeded newUser ->
{ model | currentUser = newUser }
|> update (InfoMessage <| "you are logged in!")
    InfoMessage userMessage ->
{ model
| message = "Hi " ++ model.currentUser ++ ", " ++ userMessage
}
-- better: directly update in branch
update : Msg -> Model -> (Model, Cmd Msg)
update msg model =
case msg of
...
LoginSucceeded newUser ->
( { model
| currentUser = newUser
, message "Hi " ++ newUser ++ ", you are logged in!"
}
, Cmd.none
)
Show your support

Clapping shows how much you appreciated Wouter In t Velt’s story.