Skip to content

Instantly share code, notes, and snippets.

View LLFourn's full-sized avatar

Lloyd Fournier LLFourn

View GitHub Profile
@LLFourn
LLFourn / deepgrep.pl
Created December 12, 2015 12:49
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],

In this particular case you don't even need a custom accessor. You can create extra constraints on your base type constraint with a where clause:

class Wizzard {
    has Int $.mana is rw where * > 0;
}

But if you did want to create a custom accessor you simply have to define a method with the same name and add the is rw trait.

method mana is rw {