Skip to content

Instantly share code, notes, and snippets.

@reactormonk
Created April 28, 2016 14:03
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/2f617e2a7fe27851ff8cea8e5da53872 to your computer and use it in GitHub Desktop.
Save reactormonk/2f617e2a7fe27851ff8cea8e5da53872 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[S](t: typedesc[seq]): S = @[]
proc zero[S](t: typedesc[int]): S = 0
proc zero[S](t: typedesc[float]): S = 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