From f2d176e0dd4926ebe733a2bb25322ac0fcf54b40 Mon Sep 17 00:00:00 2001 From: Dummi26 Date: Thu, 9 Mar 2023 13:26:54 +0100 Subject: [PATCH] added another example to the readme, showing switch statements --- README.md | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/README.md b/README.md index 3bded25..1e01482 100644 --- a/README.md +++ b/README.md @@ -46,6 +46,28 @@ run() will return what the function returns while thread() will return a Thread ## Examples +### Switching on an unknown type. + + string = false + var = if string "test string" else -1 + + print_int = (num int) num.to_string().print() + + debug( var ) + + switch! var { + string { + print("String:") + print( var ) + } + int { + print("integer:") + print_int.run( var ) + } + } + +using switch! forces you to cover all possible types. Try removing the string or int case and see what happens! + ### Running a thread and awaiting it, passing arguments to the thread when starting it and sharing a variable because the thread's function captured it (useful for reporting progress, i.e. changing a float from 0.0 to 100.0 while downloading and using the main thread to animate a progress bar, then using .await() only when the float is set to 100 to avoid blocking) print( "Starting" )