This commit is contained in:
Araq 2012-05-30 22:37:17 +02:00
commit 04300542da
3 changed files with 30 additions and 6 deletions

View file

@ -1,5 +1,5 @@
discard """
output: "0false"
output: "0false12"
"""
# Test multiple generic instantiation of generic proc vars:
@ -17,3 +17,20 @@ proc threadProcWrapper[TMsg]() =
threadProcWrapper[int]()
threadProcWrapper[bool]()
type
TFilterProc[T,D] = proc (item: T, env:D): bool
proc filter[T,D](data: seq[T], env:D, pred: TFilterProc[T,D]): seq[T] =
result = @[]
for e in data:
if pred(e, env): result.add(e)
proc predTest(item: int, value: int): Bool =
return item <= value
proc test(data: seq[int], value: int): seq[int] =
return filter(data, value, predTest)
for x in items(test(@[1,2,3], 2)):
stdout.write(x)