-
-
Save reactormonk/2f617e2a7fe27851ff8cea8e5da53872 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[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