summary refs log blame commit diff stats
path: root/examples/allany.nim
blob: de36a1d9bdb850b45dc1e7e1da4051f67457ec0a (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11

             
                                                         

                     

                               



                      
                                                         








                                                                     




                      
# All and any

template all(container, cond: expr): expr {.immediate.} =
  block:
    var result = true
    for it in items(container):
      if not cond(it):
        result = false
        break
    result

template any(container, cond: expr): expr {.immediate.} =
  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"