allany.nim 448 B

12345678910111213141516171819202122232425
  1. # All and any
  2. template all(container, cond: untyped): bool =
  3. var result = true
  4. for it in items(container):
  5. if not cond(it):
  6. result = false
  7. break
  8. result
  9. template any(container, cond: untyped): bool =
  10. var result = false
  11. for it in items(container):
  12. if cond(it):
  13. result = true
  14. break
  15. result
  16. if all("mystring", {'a'..'z'}.contains) and any("myohmy", 'y'.`==`):
  17. echo "works"
  18. else:
  19. echo "does not work"