tenumerate.nim 455 B

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