Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@havarnov
Created October 13, 2016 19:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save havarnov/a4fb9952c17d1dcdc8a8c96bf7a0896d to your computer and use it in GitHub Desktop.
Save havarnov/a4fb9952c17d1dcdc8a8c96bf7a0896d to your computer and use it in GitHub Desktop.
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