blob: 0d4a399c580aa35bf11bbccb72d89da7637ee0eb (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
discard """
output: '''b yields
c yields
a returns
b yields
b returns
c yields
1
2
3
4
'''
"""
block:
template tloop(iter: untyped) =
for i in iter():
echo i
template twhile(iter: untyped) =
let it = iter
while not finished(it):
echo it()
iterator a(): auto {.closure.} =
if true: return "a returns"
yield "a yields"
iterator b(): auto {.closure.} =
yield "b yields"
if true: return "b returns"
iterator c(): auto {.closure.} =
yield "c yields"
if true: return
iterator d(): auto {.closure.} =
if true: return
yield "d yields"
tloop(a)
tloop(b)
tloop(c)
tloop(d)
twhile(a)
twhile(b)
twhile(c)
twhile(d)
block:
iterator a: auto =
yield 1
for x in a():
echo x
let b = iterator: int =
yield 2
for x in b():
echo x
let c = iterator: auto =
yield 3
for x in c():
echo x
block:
iterator myIter2(): auto {.closure.} =
yield 4
for a in myIter2():
echo a
block t5859:
proc flatIterator[T](s: openarray[T]): auto {.noSideEffect.}=
result = iterator(): auto =
when (T is not seq|array):
for item in s:
yield item
else:
yield 123456
# issue #5859
let it = flatIterator(@[@[1,2], @[3,4]])
|