reimplement_pr_10974 (#11130)
This commit is contained in:
parent
69755542f4
commit
3647c03cad
2 changed files with 19 additions and 0 deletions
|
|
@ -158,6 +158,9 @@ proc enumToString*(enums: openArray[enum]): string =
|
||||||
|
|
||||||
- Added `system.default`.
|
- Added `system.default`.
|
||||||
|
|
||||||
|
- Added `sequtils.items` for closure iterators, allows closure iterators
|
||||||
|
to be used by the the mapIt, filterIt, allIt, anyIt, etc.
|
||||||
|
|
||||||
|
|
||||||
### Library changes
|
### Library changes
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -949,6 +949,14 @@ macro mapLiterals*(constructor, op: untyped;
|
||||||
## works for nested tuples of arrays of sets etc.
|
## works for nested tuples of arrays of sets etc.
|
||||||
result = mapLitsImpl(constructor, op, nested.boolVal)
|
result = mapLitsImpl(constructor, op, nested.boolVal)
|
||||||
|
|
||||||
|
iterator items*[T](xs: iterator: T): T =
|
||||||
|
## iterates over each element yielded by a closure iterator. This may
|
||||||
|
## not seem particularly useful on its own, but this allows closure
|
||||||
|
## iterators to be used by the the mapIt, filterIt, allIt, anyIt, etc.
|
||||||
|
## templates.
|
||||||
|
for x in xs():
|
||||||
|
yield x
|
||||||
|
|
||||||
when isMainModule:
|
when isMainModule:
|
||||||
import strutils
|
import strutils
|
||||||
from algorithm import sorted
|
from algorithm import sorted
|
||||||
|
|
@ -1382,5 +1390,13 @@ when isMainModule:
|
||||||
doAssert outp == @[@["a", "b"], @["c", "d"]]
|
doAssert outp == @[@["a", "b"], @["c", "d"]]
|
||||||
|
|
||||||
|
|
||||||
|
block:
|
||||||
|
proc iter(len: int): auto =
|
||||||
|
result = iterator(): int =
|
||||||
|
for i in 0..<len:
|
||||||
|
yield i
|
||||||
|
|
||||||
|
doAssert: iter(3).mapIt(2*it).foldl(a + b) == 6
|
||||||
|
|
||||||
when not defined(testing):
|
when not defined(testing):
|
||||||
echo "Finished doc tests"
|
echo "Finished doc tests"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue