Skip to content

Instantly share code, notes, and snippets.

View macro-when.raku
use v6.d;
multi sub _when(Int $i) { dd $i; }
multi sub _when($_ where $_ ~~ /(\w+)/) { say $0 }
given 42 {
$_.&_when;
}
given 'word' {
View expose-payload.raku
use v6.e.PREVIEW;
use Test;
{
CONTROL {
when CX::Take { is .payload, 'take', payload is exposed for CX::Take }
}
take 'take';
View 2021-03-08.raku
my @a = <1 B 3 D 4>;
my @b;
my $hit;
for @a -> $e {
@b.push: ($e ~~ m/(<alpha>) || { next } /).Str;
}
say @b;
View so-66233465.raku
class Hold { has $.key; }
class Press { has $.key; }
class Err { has $.msg; }
sub else(&code) { &code }
sub match($needle, *@tests) {
for @tests.head(*-1) -> &f {
if &f.cando(\($needle)) {
f($needle);
View DeclaratorProxy.rakumod
use nqp;
class Metamodel::ProxyHOW is Metamodel::ClassHOW {
method compose(Mu $type-obj is raw) {
say composing a Metamodel::ProxyHOW;
my %m = $type-obj.^methods.map({ slip .name, $_ });
# $type-obj.^add_method('new', sub ($type) {
# nqp::create(nqp::decont($type));
View any-chain.raku
use v6.e.PREVIEW;
use MONKEY-TYPING;
# augment class Any {
# method chain {
# class Chainer {
# has $.the-object;
# method FALLBACK($name, *@a) {
# my $o = $.the-object;
# if @a {
View tmp2.raku
use v6.e.PREVIEW;
my @a = <a b>;
my %b;
%b{||@a} = 42;
@a = <a b c>;
%b{||@a} = 42; # line 7
# OUTPUT: Type Int does not support associative indexing.
# in block <unit> at /home/dex/projects/raku/rakudobug/tmp2.raku line 7
View mop-metamethod.raku
class InterceptHOW is Metamodel::ClassHOW {
method publish_method_cache(|) { }
}
sub ipry(Mu $the-object is raw) {
# use InterceptAllMethods;
# class Interceptor {
# has Mu $!the-object;
# method ^find_method(Mu \type, Str $name) {
View gfldex-been-naughty.raku
sub pry(Mu $the-object is raw) {
class :: is Mu {
has $.the-object;
method WHY { 'This is a wrapper for `sub pry` around ' ~ $.the-object.WHAT.gist ~ '.' }
method gist { self.WHY }
method FALLBACK($name) is rw {
say $name was called;
use nqp;
nqp::getattr($.the-object, $.the-object.WHAT, '$!' ~ $name)
}
View any-chain.raku
use MONKEY-TYPING;
augment class Any {
method chain {
class Chainer {
has $.the-object;
method FALLBACK($name, *@a) {
my $o = $.the-object;
if @a {
for @a -> $e {