tenumerate.nim 526 B

12345678910111213141516171819202122232425
  1. discard """
  2. matrix: "--mm:refc; --mm:orc"
  3. """
  4. import std/enumerate
  5. import std/assertions
  6. let a = @[1, 3, 5, 7]
  7. block:
  8. var res: seq[(int, int)]
  9. for i, x in enumerate(a):
  10. res.add (i, x)
  11. doAssert res == @[(0, 1), (1, 3), (2, 5), (3, 7)]
  12. block:
  13. var res: seq[(int, int)]
  14. for (i, x) in enumerate(a.items):
  15. res.add (i, x)
  16. doAssert res == @[(0, 1), (1, 3), (2, 5), (3, 7)]
  17. block:
  18. var res: seq[(int, int)]
  19. for i, x in enumerate(3, a):
  20. res.add (i, x)
  21. doAssert res == @[(3, 1), (4, 3), (5, 5), (6, 7)]