titerconcat.nim 320 B

12345678910111213141516171819202122232425
  1. discard """
  2. output: '''1
  3. 2
  4. 3
  5. 4
  6. 20
  7. 21
  8. 22
  9. 23'''
  10. """
  11. proc toIter*[T](s: Slice[T]): iterator: T =
  12. iterator it: T {.closure.} =
  13. for x in s.a..s.b:
  14. yield x
  15. return it
  16. iterator concat*[T](its: varargs[T, toIter]): auto =
  17. for i in its:
  18. for x in i():
  19. yield x
  20. for i in concat(1..4, 20..23):
  21. echo i