next steps for closure iterators
This commit is contained in:
parent
85a5bfe605
commit
37229df7fc
28 changed files with 164 additions and 71 deletions
32
tests/iter/tanoniter1.nim
Normal file
32
tests/iter/tanoniter1.nim
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
discard """
|
||||
output: '''1
|
||||
2
|
||||
3
|
||||
4
|
||||
1
|
||||
2'''
|
||||
"""
|
||||
|
||||
proc factory(a, b: int): iterator (): int =
|
||||
iterator foo(): int =
|
||||
var x = a
|
||||
while x <= b:
|
||||
yield x
|
||||
inc x
|
||||
return foo
|
||||
|
||||
proc factory2(a, b: int): iterator (): int =
|
||||
return iterator (): int =
|
||||
var x = a
|
||||
while x <= b:
|
||||
yield x
|
||||
inc x
|
||||
|
||||
let foo = factory 1, 4
|
||||
|
||||
for f in foo():
|
||||
echo f
|
||||
|
||||
let foo2 = factory2 1,2
|
||||
|
||||
for f in foo2(): echo f
|
||||
Loading…
Add table
Add a link
Reference in a new issue