Skip to content

Instantly share code, notes, and snippets.

@evilz
Created February 5, 2022 14:31
Show Gist options
  • Save evilz/2e4f7d2914aedafe656b5842d5186f63 to your computer and use it in GitHub Desktop.
Save evilz/2e4f7d2914aedafe656b5842d5186f63 to your computer and use it in GitHub Desktop.
Elmish console counter in 30 lines
#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