titeropenarray.nim 678 B

123456789101112131415161718192021222324252627282930313233
  1. block: # issue #13417
  2. var s: seq[int] = @[]
  3. proc p1(): seq[int] =
  4. s.add(3)
  5. @[1,2]
  6. iterator ip1(v: openArray[int]): auto =
  7. for x in v:
  8. yield x
  9. for x in ip1(p1()):
  10. s.add(x)
  11. doAssert s == @[3, 1, 2]
  12. import std / sequtils
  13. block: # issue #19703
  14. iterator combinations[T](s: seq[T], r: Positive): seq[T] =
  15. yield @[s[0], s[1]]
  16. iterator pairwise[T](s: openArray[T]): seq[T] =
  17. yield @[s[0], s[0]]
  18. proc checkSpecialSubset5(s: seq[int]): bool =
  19. toSeq(
  20. toSeq(
  21. s.combinations(2)
  22. ).map(proc(a: auto): int = a[0]).pairwise()
  23. ).any(proc(a: auto): bool = a == @[s[0], s[0]])
  24. doAssert checkSpecialSubset5 @[1, 2]