Created
July 7, 2019 07:40
-
-
Save zah/3db08f914ac030218bb1bb8bdf6dd8ac to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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