Skip to content

Instantly share code, notes, and snippets.

@reactormonk
Created April 14, 2016 10:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save reactormonk/cab00e6420d9f0074f39cd67bf908067 to your computer and use it in GitHub Desktop.
Save reactormonk/cab00e6420d9f0074f39cd67bf908067 to your computer and use it in GitHub Desktop.
import sequtils
proc append[T](a, b: T): T = a + b
proc append[T: seq](a, b: T): T = concat(a, b)
proc zero[T: typedesc[seq]](): T = @[]
proc zero[T: typedesc[int]](): T = 0
proc zero[T: typedesc[float]](): T = 0.0
proc multiply[T: typedesc](t: T, times: int): T =
if times <= 0:
zero[T]()
else:
for i in 1..times:
result = append(result, t)
echo(multiply(3, 3))
echo(multiply(@[1, 2, 3], 3))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment