SHARE
TWEET

Untitled

a guest Jul 18th, 2019 45 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top