Created
February 5, 2022 14:31
-
-
Save evilz/2e4f7d2914aedafe656b5842d5186f63 to your computer and use it in GitHub Desktop.
Elmish console counter in 30 lines
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
#r "nuget: Elmish, 3.1.0" | |
#r "nuget: Terminal.Gui.Elmish, 0.1.8-preview1" | |
open System | |
open Elmish | |
type Model = { Count: int } | |
type Messages = | |
| Incr | |
| Decr | |
let update msg model = | |
match msg with | |
| Incr -> { Count = model.Count + 1 } | |
| Decr -> { Count = model.Count - 1 } | |
let init () = { Count = 0 } | |
let rec view model dispatch = | |
printfn $"Count: {model.Count}" | |
let input = Console.ReadLine() | |
if input = "+" then dispatch Incr | |
else if input = "-" then dispatch Decr | |
else view model dispatch | |
Program.mkSimple init update view |> Program.run |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment