Files
Nim/examples/allany.nim
2018-05-28 19:45:12 +02:00

25 lines
448 B
Nim

# All and any
template all(container, cond: untyped): bool =
var result = true
for it in items(container):
if not cond(it):
result = false
break
result
template any(container, cond: untyped): bool =
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"