Skip to content

Instantly share code, notes, and snippets.

@LLFourn
Created December 12, 2015 12:49
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 LLFourn/99f4ccf32de604bc61b2 to your computer and use it in GitHub Desktop.
Save LLFourn/99f4ccf32de604bc61b2 to your computer and use it in GitHub Desktop.
recursively grep arrays with test
use v6;
sub deepgrep(&test,@array) {
@array.map: {
when Positional { |deepgrep(&test, $_) }
default { $_ when test $_ }
}
}
say deepgrep * %% 2, [[1], 2, [[3,4], 5],
[[[]]], [[[6]]], 7, 8, []];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment