fuzion-lang.dev — The Fuzion Language Portal
JavaScript seems to be disabled. Functionality is limited.
Fuzion
•
Idioms
•
Idiom # 206: Switch statement with strings
Idiom # 206: Switch statement with strings
See
programming-idioms.org
:
Code
((container.ordered_map ["foo", "bar", "baz", "barfl" ] [foo, bar, baz, barfl])[str].unwrap.call) # NYI: This will need some syntax improvements: # # 1. better syntax for inline maps # 2. better syntax for inline funtions # 3. automatic unwrap and call # # example: # # switch str ["foo" => foo # "bar" => bar # "baz" => baz # "barfl" => barfl] # # where 'switch' is a feature declared similar to # # switch
(on T, m map
U) => # m[on].unwrap.call #
What are effects?
Running Example
ex206 is foo Function unit => ()->say "foo" bar Function unit => ()->say "bar" baz Function unit => ()->say "baz" barfl Function unit => ()->say "barfl" for str in ["bar", "foo", "barfl", "baz", "error" /* will cause a precondition failure! */] do ((container.ordered_map ["foo", "bar", "baz", "barfl" ] [foo, bar, baz, barfl])[str].get.call) # NYI: better syntax, e.g., # # switch str ["foo" => foo # "bar" => bar # "baz" => baz # "barfl" => barfl]
What are effects?
last changed: 2024-07-01
next: Idiom # 207: allocate a list that is automatically deallocated