We can match something like ("e", _) | ("exit", _) | ("q", _) | ("quit", _) -> but we should be able to compress that pattern and instead match: ("e" | "exit" | "q" | "quit", _) ->.
Sample code that should work:
app [main] { pf: platform "https://github.com/roc-lang/basic-cli/releases/download/0.15.0/SlwdbJ-3GR7uBWQo6zlmYWNYOxnvo8r6YABXD-45UOw.tar.br" }
import pf.Stdout
import pf.Stdin
main = getChoice
options = ["parse", "validate", "analyze", "analyze and correct"]
menu =
options
|> List.mapWithIndex \option, index ->
"$(Num.toStr (index + 1)). $(option)"
|> Str.joinWith "\n"
getChoice =
Task.loop {} \{} ->
Stdout.line! "\nPlease enter a number for an option below:\n\n$(menu)"
Stdout.write! "\n> "
choice = Stdin.line!
optionRes =
choiceNum = Str.toU64? choice
List.get options choiceNum
when (choice, optionRes) is
("e" | "exit" | "q" | "quit", _) ->
Task.ok (Done {})
(_, Ok option) ->
Stdout.line! option
Task.ok (Done {})
(_, _) ->
Stdout.line! "\nOops, that's not an option."
Task.ok (Step {})
We can match something like
("e", _) | ("exit", _) | ("q", _) | ("quit", _) ->
but we should be able to compress that pattern and instead match:("e" | "exit" | "q" | "quit", _) ->
.Sample code that should work: