titerable.nim 446 B

123456789101112131415161718192021222324252627282930
  1. discard """
  2. output: '''2
  3. 4
  4. 6
  5. 4
  6. 8
  7. 12
  8. '''
  9. disabled: "true"
  10. """
  11. # Will eventually fix it...
  12. iterator map[T, U](s: iterator:T{.inline.}, f: proc(x: T): U): U =
  13. for e in s: yield f(e)
  14. template toSeq(s: untyped): untyped =
  15. var res = newSeq[type(s)](0)
  16. for e in s: res.add(e)
  17. res
  18. var s1 = @[1, 2, 3]
  19. for x in map(s1.items, proc (a:int): int = a*2):
  20. echo x
  21. var s2 = toSeq(map(s1.items, proc (a:int): int = a*4))
  22. for x in s2:
  23. echo x