I have this following code snippet in my Elm code:
type alias Model =
{ content : String
}
update : Msg -> Model -> Model
update msg model =
case msg of
Change newContent ->
{ model | content = newContent }
What does { model | content = newContent } do?
Does it assign (bind) the value of newContent to model as well as content? Is that why the | operator is placed there?
The pipe is not a part of the case expression. It's record update syntax, as described here: https://elm-lang.org/docs/records#updating-records.
{ model | content = newContent }
assigns the value of newContent to the content field in the model record.
Read | as 'with'.
{ model 'with' content (set to) = newContent }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With