summary refs log tree commit diff stats
path: root/tests/generics/tgenericprocvar.nim
blob: 1eba81fec477768f0cdb92a08ea72edc2cd8ead8 (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
discard """
  output: "0false12"
"""

# Test multiple generic instantiation of generic proc vars:

proc threadProcWrapper[TMsg]() =
  var x: TMsg
  stdout.write($x)

#var x = threadProcWrapper[int]
#x()

#var y = threadProcWrapper[bool]
#y()

threadProcWrapper[int]()
threadProcWrapper[bool]()

type
  TFilterProc[T,D] = proc (item: T, env:D): bool {.nimcall.}

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)