Created
May 5, 2016 21:41
-
-
Save halfzebra/2bfb8e8a996b9e12df93427bccc10ec9 to your computer and use it in GitHub Desktop.
Generalized function to handle updates of the Dictionary
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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