Skip to content

Instantly share code, notes, and snippets.

@zah
Created July 7, 2019 07:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zah/3db08f914ac030218bb1bb8bdf6dd8ac to your computer and use it in GitHub Desktop.
Save zah/3db08f914ac030218bb1bb8bdf6dd8ac to your computer and use it in GitHub Desktop.
import
sets
type
AlwaysMatch = object
proc match(val: string, values: HashSet[string]): bool =
val in values
proc match(val: string, predicate: proc(x: string): bool): bool =
predicate(val)
template match(val: string, T: type AlwaysMatch): bool =
true
proc walkDirRec(filter: auto = AlwaysMatch) =
mixin match
if match("dir_name", filter):
echo "we have a match"
else:
echo "no match"
walkDirRec toHashSet(["foo", "bar", "baz"])
walkDirRec toHashSet(["file_name", "dir_name"])
walkDirRec()
walkDirRec do (x: string) -> bool:
echo "matching ", x
return true
walkDirRec do (x: string) -> bool:
echo "matching ", x
return false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment