Created
October 22, 2017 13:49
-
-
Save Yardanico/0146665df88e0d1658b07084050f1849 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
type | |
Iterable[T] = concept it | |
# items() iterator | |
for item in items(it): | |
type(item) is T | |
proc cycle*[T](s: Iterable[T], n: Natural): seq[T] = | |
when compiles(s.len): | |
result = newSeqOfCap[T](n * s.len) | |
else: | |
result = newSeqOfCap[T](n) | |
for x in 0..<n: | |
for e in s: | |
result.add(e) | |
let a = cycle(@[1, 2, 3, 4], 5) | |
echo a |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment