Created
October 13, 2016 19:26
-
-
Save havarnov/a4fb9952c17d1dcdc8a8c96bf7a0896d to your computer and use it in GitHub Desktop.
This file contains 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
module Main exposing (..) | |
import Html exposing (Html, div, button, text) | |
import Html.App exposing (beginnerProgram) | |
import Html.Events exposing (onClick) | |
main : Program Never | |
main = | |
beginnerProgram { model = init, view = view, update = update } | |
type alias Model = | |
Maybe (List Int) | |
init : Model | |
init = | |
Nothing | |
view : Model -> Html Msg | |
view model = | |
div [] | |
[ button [ onClick Add ] [ text "add" ] | |
, div [] [ text (toString model) ] | |
] | |
type Msg | |
= Add | |
update : Msg -> Model -> Model | |
update msg model = | |
case msg of | |
Add -> | |
case model of | |
Just l -> | |
let | |
i = | |
Maybe.withDefault 42 (Maybe.map (\i -> i + 1) (List.head l)) | |
l = | |
i :: l | |
in | |
Just l | |
Nothing -> | |
Just [ 1 ] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment