Skip to content

Instantly share code, notes, and snippets.

@halfzebra
Created May 5, 2016 21:41
Show Gist options
  • Save halfzebra/2bfb8e8a996b9e12df93427bccc10ec9 to your computer and use it in GitHub Desktop.
Save halfzebra/2bfb8e8a996b9e12df93427bccc10ec9 to your computer and use it in GitHub Desktop.
Generalized function to handle updates of the Dictionary
import Graphics.Element exposing (show)
import Dict exposing (Dict)
type alias Model = Dict String Int
initModel : Model
initModel =
Dict.fromList
[ ("x", 0)
, ("y", 0)
, ("z", 0)
]
updateModel : List (String, Int) -> Model -> Model
updateModel update model =
Dict.union (Dict.fromList update) model
-- Custom infix operator for Tuples.
(=>) : a -> b -> ( a, b )
(=>) =
(,)
main =
initModel
|> updateModel [ "x" => 1, "z" => 10 ]
|> updateModel [ "x" => 5, "y" => 15, "z" => 0 ]
|> updateModel [ "x" => 25 ]
|> Dict.get "x"
|> Maybe.withDefault 0
|> show
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment