Union types
Union types are types that
src/strings.duck
use std::io::println;
fn main() {
let int_or_string: Int | String = 10;
match int_or_string {
Int @i => println(f"it is an int. value: {i.to_string()}"),
String @s => println(f"it is a string. value: {s}"),
}
// Matches must be exhaustive. If you want to have a "fallthrough" case, use else
int_or_string = "hello";
match int_or_string {
Int @i => println(f"it is an int. value: {i.to_string()}"),
else => println("it was something else"),
}
// The else branch can also take an identifier
match int_or_string {
Int @i => println(f"it is an int. value: {i.to_string()}"),
else @other => println(f"it was something else: {other.to_string()}"),
}
}