Advertisement
Guest User

Untitled

a guest
Jul 18th, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. import
  2. sets
  3.  
  4. type
  5. AlwaysMatch = object
  6.  
  7. proc match(val: string, values: HashSet[string]): bool =
  8. val in values
  9.  
  10. proc match(val: string, predicate: proc(x: string): bool): bool =
  11. predicate(val)
  12.  
  13. template match(val: string, T: type AlwaysMatch): bool =
  14. true
  15.  
  16. proc walkDirRec(filter: auto = AlwaysMatch) =
  17. mixin match
  18.  
  19. if match("dir_name", filter):
  20. echo "we have a match"
  21. else:
  22. echo "no match"
  23.  
  24. walkDirRec toHashSet(["foo", "bar", "baz"])
  25. walkDirRec toHashSet(["file_name", "dir_name"])
  26.  
  27. walkDirRec()
  28.  
  29. walkDirRec do (x: string) -> bool:
  30. echo "matching ", x
  31. return true
  32.  
  33. walkDirRec do (x: string) -> bool:
  34. echo "matching ", x
  35. return false
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement