Skip to content

Instantly share code, notes, and snippets.

@modularbot
Created April 26, 2024 17:35
Show Gist options
  • Save modularbot/1a5beaf165761b55e2f743b3151210eb to your computer and use it in GitHub Desktop.
Save modularbot/1a5beaf165761b55e2f743b3151210eb to your computer and use it in GitHub Desktop.
from utils.variant import Variant
fn print_value(value: Variant[Int, StringLiteral], end: StringLiteral) -> None:
if value.isa[Int]():
print(value.get[Int]()[], end=end)
else:
print(value.get[StringLiteral]()[], end=end)
fn main() -> None:
var a = List[Variant[Int, StringLiteral]](1, "Hi", 3, "Hello", 5)
print("List(", end="")
for i in range(len(a) - 1):
print_value(a[i], ", ")
print_value(a[-1], "")
print(")")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment