mirror of
https://github.com/roc-lang/roc.git
synced 2024-11-11 05:34:11 +03:00
Add countdown example
This commit is contained in:
parent
0079f8f45c
commit
97149d4530
1
examples/cli/.gitignore
vendored
1
examples/cli/.gitignore
vendored
@ -1,2 +1,3 @@
|
|||||||
|
countdown
|
||||||
echo
|
echo
|
||||||
form
|
form
|
||||||
|
18
examples/cli/countdown.roc
Normal file
18
examples/cli/countdown.roc
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
app "countdown"
|
||||||
|
packages { pf: "platform" }
|
||||||
|
imports [ pf.Stdin, pf.Stdout, pf.Task.{ await, loop, succeed } ]
|
||||||
|
provides [ main ] to pf
|
||||||
|
|
||||||
|
main =
|
||||||
|
_ <- await (Stdout.line "\nLet's count down from 10 together - all you have to do is press <ENTER>.")
|
||||||
|
_ <- await Stdin.line
|
||||||
|
loop 10 tick
|
||||||
|
|
||||||
|
tick = \n ->
|
||||||
|
if n == 0 then
|
||||||
|
_ <- await (Stdout.line "🎉 SURPRISE! Happy Birthday! 🎂")
|
||||||
|
succeed (Done {})
|
||||||
|
else
|
||||||
|
_ <- await (n |> Num.toStr |> \s -> "\(s)..." |> Stdout.line)
|
||||||
|
_ <- await Stdin.line
|
||||||
|
succeed (Step (n - 1))
|
Loading…
Reference in New Issue
Block a user