Let me try to answer that, though I don’t have the compiler at hand right
now for checking this code works exactly:

update msg ({ entries } as model) =
    let
        updateEntry =
            case msg of
                ToggleDone id ->
                    Dict.update id (Maybe.map (\({ done } as t) -> { t
| done = not done }))

                UpdateTaskName id newTaskName ->
                    Dict.update id (Maybe.map (\t -> { t | name =
newTaskName }))
    in
        { model | entries = updateEntry entries }

​

2016-09-03 16:11 GMT+02:00 Brian John Farrar <[email protected]>:

> Thanks all for the responses.
>
> For:
> "Maybe.map doesn't appear useful as record updates aren't compose-able?)"
>
> I'll reformulate the question: What is the most factored version of the
> following code?
>
> update msg model =
>     case msg of
>         ToggleDone id ->
>             let
>                 updateEntry t =
>                     case t of
>                         Nothing ->
>                             Nothing
>
>                         Just t ->
>                             Just { t | done = not t.done }
>             in
>                 { model | entries = Dict.update id updateEntry
> model.entries }
>
>         UpdateTaskName id newTaskName ->
>             let
>                 updateEntry t =
>                     case t of
>                         Nothing ->
>                             Nothing
>
>                         Just t ->
>                             Just { t | name = newTaskName }
>             in
>                 { model | entries = Dict.update id updateEntry
> model.entries }
>
>
>> --
> You received this message because you are subscribed to the Google Groups
> "Elm Discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to