diff options
author | jrfondren <41455523+jrfondren@users.noreply.github.com> | 2019-05-03 13:03:45 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-05-03 13:03:45 -0500 |
commit | 8cadeb960597a47a09100bdda05672f177d158d2 (patch) | |
tree | afe59c7bc9f5502801754e0f7fead84552a3d4e6 /lib/pure/collections/sequtils.nim | |
parent | 6dfde0e931176405491987e14969f68d81957730 (diff) | |
parent | 515ab81477c1c3e4811c4fbf43a3ff81b87be970 (diff) | |
download | Nim-8cadeb960597a47a09100bdda05672f177d158d2.tar.gz |
Merge branch 'devel' into expand-amb-identifier-output
Diffstat (limited to 'lib/pure/collections/sequtils.nim')
-rw-r--r-- | lib/pure/collections/sequtils.nim | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/lib/pure/collections/sequtils.nim b/lib/pure/collections/sequtils.nim index 253340379..e39c1fb80 100644 --- a/lib/pure/collections/sequtils.nim +++ b/lib/pure/collections/sequtils.nim @@ -949,6 +949,14 @@ macro mapLiterals*(constructor, op: untyped; ## works for nested tuples of arrays of sets etc. 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: import strutils from algorithm import sorted @@ -1382,5 +1390,13 @@ when isMainModule: 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): echo "Finished doc tests" |