Skip to content

Instantly share code, notes, and snippets.

@Yardanico
Created October 22, 2017 13:49
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 Yardanico/0146665df88e0d1658b07084050f1849 to your computer and use it in GitHub Desktop.
Save Yardanico/0146665df88e0d1658b07084050f1849 to your computer and use it in GitHub Desktop.
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