made closure iterators tests green, updated docs
This commit is contained in:
parent
2162a71c93
commit
307a6095fa
10 changed files with 42 additions and 35 deletions
|
|
@ -9,7 +9,7 @@ proc univ(x, y: int): State = Tree
|
|||
|
||||
var w, h = 30
|
||||
|
||||
iterator fields(a = (0,0), b = (h-1,w-1)) =
|
||||
iterator fields(a = (0,0), b = (h-1,w-1)): auto =
|
||||
for y in max(a[0], 0) .. min(b[0], h-1):
|
||||
for x in max(a[1], 0) .. min(b[1], w-1):
|
||||
yield (y,x)
|
||||
|
|
|
|||
|
|
@ -14,11 +14,7 @@ discard """
|
|||
49
|
||||
64
|
||||
81
|
||||
--- squares of evens, only
|
||||
4
|
||||
16
|
||||
36
|
||||
64'''
|
||||
'''
|
||||
"""
|
||||
|
||||
iterator `/`[T](sequence: seq[T],
|
||||
|
|
@ -40,10 +36,10 @@ iterator `/>>`[I,O](sequence: seq[I],
|
|||
if (filtermap.f(element)):
|
||||
yield filtermap.m(element)
|
||||
|
||||
proc isEven(x:int): bool {.closure.} = result =
|
||||
proc isEven(x:int): bool =
|
||||
(x and 1) == 0
|
||||
|
||||
proc square(x:int): int {.closure.} = result =
|
||||
proc square(x:int): int =
|
||||
x * x
|
||||
|
||||
let list = @[1,2,3,4,5,6,7,8,9]
|
||||
|
|
@ -52,6 +48,6 @@ echo ("--- evens")
|
|||
for item in list / isEven : echo(item)
|
||||
echo ("--- squares")
|
||||
for item in list >> square : echo(item)
|
||||
echo ("--- squares of evens, only")
|
||||
#echo ("--- squares of evens, only")
|
||||
# next line doesn't compile. Generic types are not inferred
|
||||
for item in list />> (isEven, square) : echo(item)
|
||||
#for item in list />> (isEven, square) : echo(item)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue