allany.nim 490 B

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