Skip to content

Instantly share code, notes, and snippets.

@PhilipWitte
Created February 17, 2015 21:15
Show Gist options
  • Save PhilipWitte/a9ecf4d36b109ee179b7 to your computer and use it in GitHub Desktop.
Save PhilipWitte/a9ecf4d36b109ee179b7 to your computer and use it in GitHub Desktop.
type A = object
type B = object
proc a(x: A) = echo "a"
proc b(x: B) = echo "b"
proc test(x: A|B) =
when x is A:
a(x)
else:
b(x)
test(A())
# --- ALTERNATIVE (using type-classes) --- #
type A = object
type B = object
proc a(x: A) = echo "a"
proc b(x: B) = echo "b"
type SomeA = generic x
a(x)
proc test(x) =
when x is SomeA:
a(x)
else:
b(x)
test(A())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment