tenumerate.nim 477 B

123456789101112131415161718192021
  1. import std/enumerate
  2. import std/assertions
  3. let a = @[1, 3, 5, 7]
  4. block:
  5. var res: seq[(int, int)]
  6. for i, x in enumerate(a):
  7. res.add (i, x)
  8. doAssert res == @[(0, 1), (1, 3), (2, 5), (3, 7)]
  9. block:
  10. var res: seq[(int, int)]
  11. for (i, x) in enumerate(a.items):
  12. res.add (i, x)
  13. doAssert res == @[(0, 1), (1, 3), (2, 5), (3, 7)]
  14. block:
  15. var res: seq[(int, int)]
  16. for i, x in enumerate(3, a):
  17. res.add (i, x)
  18. doAssert res == @[(3, 1), (4, 3), (5, 5), (6, 7)]