-
-
Save reactormonk/cab00e6420d9f0074f39cd67bf908067 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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