ttupleunpack.nim 458 B

123456789101112131415161718192021222324252627282930
  1. proc returnsTuple(): (int, int, int) = (4, 2, 3)
  2. proc main2 =
  3. let (x, _, z) = returnsTuple()
  4. proc main() =
  5. proc foo(): tuple[x, y, z: int] =
  6. return (4, 2, 3)
  7. var (x, _, y) = foo()
  8. doAssert x == 4
  9. doAssert y == 3
  10. var (a, _, _) = foo()
  11. doAssert a == 4
  12. var (aa, _, _) = foo()
  13. doAssert aa == 4
  14. iterator bar(): tuple[x, y, z: int] =
  15. yield (1,2,3)
  16. for x, y, _ in bar():
  17. doAssert x == 1
  18. doAssert y == 2
  19. main()
  20. main2()