mirror of
https://github.com/Dummi26/mers.git
synced 2025-03-10 14:13:52 +01:00
added another example to the readme, showing switch statements
This commit is contained in:
parent
63721b9e26
commit
f2d176e0dd
22
README.md
22
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" )
|
||||
|
Loading…
Reference in New Issue
Block a user