summary refs log tree commit diff stats
path: root/examples/allany.nim
blob: 6ff055aa667b9b049d9e9a88d2a509f1aaca2a36 (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
# All and any

template all(container, cond: untyped): bool =
  block:
    var result = true
    for it in items(container):
      if not cond(it):
        result = false
        break
    result

template any(container, cond: untyped): bool =
  block:
    var result = false
    for it in items(container):
      if cond(it):
        result = true
        break
    result

if all("mystring", {'a'..'z'}.contains) and any("myohmy", 'y'.`==`):
  echo "works"
else:
  echo "does not work"