Skip to content

Instantly share code, notes, and snippets.

@lucamug
Last active January 1, 2020 01:11
Show Gist options
  • Save lucamug/5fb5ad9379a3c2dea4677428db656187 to your computer and use it in GitHub Desktop.
Save lucamug/5fb5ad9379a3c2dea4677428db656187 to your computer and use it in GitHub Desktop.
module Main exposing (main)
import Browser
import Html exposing (..)
import Html.Attributes exposing (..)
import Html.Events exposing (..)
init = { a = "1", b = "2" }
type Msg = ChangeA String | ChangeB String
update msg model =
case msg of
ChangeA value -> { model | a = value }
ChangeB value -> { model | b = value }
view model =
div []
[ input [ onInput ChangeA, value model.a, type_ "number"] []
, input [ onInput ChangeB, value model.b, type_ "number"] []
, p []
[ text <| String.join " "
[ model.a
, "+"
, model.b
, "="
, case Maybe.map2 (+) (String.toFloat model.a) (String.toFloat model.b) of
Just value -> String.fromFloat value
Nothing -> "undefined"
]
]
]
main = Browser.sandbox { init = init, view = view, update = update }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment