Skip to content

Instantly share code, notes, and snippets.

@joakimk joakimk/Update.elm
Last active Sep 22, 2016

What would you like to do?
One attempt at simple adding or updating a record in a list in Elm
import UpdateList exposing (addOrUpdateById)
update msg model =
case msg of
NewOrUpdatedItem item ->
({model | items = model.items |> addOrUpdateById item}, Cmd.none)
module UpdateList exposing (addOrUpdateById)
type alias Identifyable a = { a | id : Int }
addOrUpdateById : Identifyable a -> List (Identifyable a) -> List (Identifyable a)
addOrUpdateById record list =
if isNewRecord record list then
List.concat [ [ record ], list ]
else (updateById record) list
updateById : Identifyable a -> Identifyable a -> Identifyable a
updateById record r =
if == then
isNewRecord : Identifyable a -> List (Identifyable a) -> Bool
isNewRecord record list =
|> (\r ->
|> List.member
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.