Moves toSeq template to public sequtils module.
This commit is contained in:
parent
77492158ac
commit
bd961fd76c
2 changed files with 11 additions and 6 deletions
|
|
@ -63,3 +63,9 @@ template filterIt*(seq1, pred: expr): expr {.immediate, dirty.} =
|
||||||
if pred: result.add(it)
|
if pred: result.add(it)
|
||||||
result
|
result
|
||||||
|
|
||||||
|
template toSeq*(iter: expr): expr {.immediate.} =
|
||||||
|
## Transforms any iterator into a sequence.
|
||||||
|
var result {.gensym.}: seq[type(iter)] = @[]
|
||||||
|
for x in iter: add(result, x)
|
||||||
|
result
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,11 @@
|
||||||
discard """
|
discard """
|
||||||
output: "23456"
|
output: "2345623456"
|
||||||
"""
|
"""
|
||||||
|
|
||||||
template toSeq*(iter: expr): expr {.immediate.} =
|
import sequtils
|
||||||
var result: seq[type(iter)] = @[]
|
|
||||||
for x in iter: add(result, x)
|
for x in toSeq(countup(2, 6)):
|
||||||
result
|
stdout.write(x)
|
||||||
|
|
||||||
for x in items(toSeq(countup(2, 6))):
|
for x in items(toSeq(countup(2, 6))):
|
||||||
stdout.write(x)
|
stdout.write(x)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue