tchainediterators.nim 660 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. discard """
  2. output: '''16
  3. 32
  4. 48
  5. 64
  6. 128
  7. 192
  8. '''
  9. disabled: "true"
  10. """
  11. # This all relies on non-documented and questionable features.
  12. iterator gaz(it: iterator{.inline.}): type(it) =
  13. for x in it:
  14. yield x*2
  15. iterator baz(it: iterator{.inline.}): auto =
  16. for x in gaz(it):
  17. yield x*2
  18. type T1 = auto
  19. iterator bar(it: iterator: T1{.inline.}): T1 =
  20. for x in baz(it):
  21. yield x*2
  22. iterator foo[T](x: iterator: T{.inline.}): T =
  23. for e in bar(x):
  24. yield e*2
  25. var s = @[1, 2, 3]
  26. # pass an iterator several levels deep:
  27. for x in s.items.foo:
  28. echo x
  29. # use some complex iterator as an input for another one:
  30. for x in s.items.baz.foo:
  31. echo x