Skip to content

Instantly share code, notes, and snippets.

@gerdr
Created June 16, 2012 19:03
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 gerdr/2942255 to your computer and use it in GitHub Desktop.
Save gerdr/2942255 to your computer and use it in GitHub Desktop.
recursive directory walking
sub dirwalk(Str $dir = '.', Mu :$d = none(<. ..>), Mu :$f = *,
:&dx = -> $ {}, :&fx = -> $ {}) {
for dir($dir, :test(*)) {
given "$dir/$_".IO but $_ {
when .f {
&fx.(.path) if $f.ACCEPTS($_)
}
when .d {
dirwalk(.path, :$d, :$f, :&dx, :&fx) if $d.ACCEPTS($_)
}
}
}
&dx.($dir);
}
my @modules = gather <lib lib6>.grep(*.IO.d).map({
dirwalk($_, :f(/\.pm6?$/), :fx(&take))
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment