Add items iterator for slices

This commit is contained in:
def
2015-04-03 11:09:56 +02:00
parent 57fa8c6d3f
commit 8faac66abe

View File

@@ -1738,6 +1738,12 @@ iterator items*(E: typedesc[enum]): E =
for v in low(E)..high(E):
yield v
iterator items*[T](s: Slice[T]): T =
## iterates over the slice `s`, yielding each value between `s.a` and `s.b`
## (inclusively).
for x in s.a..s.b:
yield x
iterator pairs*[T](a: openArray[T]): tuple[key: int, val: T] {.inline.} =
## iterates over each item of `a`. Yields ``(index, a[index])`` pairs.
var i = 0