Skip to content

Instantly share code, notes, and snippets.

@gfldex
Created January 25, 2021 21:30
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 gfldex/9e45f51cdb346e5e6e026fe8bdd0e5bc to your computer and use it in GitHub Desktop.
Save gfldex/9e45f51cdb346e5e6e026fe8bdd0e5bc to your computer and use it in GitHub Desktop.
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 {
$o = $o."$name"($e, |%_);
}
} elsif %_ {
for %_ -> %p {
$o = $o."$name"(|%p);
}
} else {
# XXX error handling
}
$o
}
}
Chainer.new(the-object => self)
}
}
IO::Path.HOW.compose(IO::Path);
DateTime.HOW.compose(DateTime);
'/home/dex'.IO.chain.add(<tmp foo.txt>).say;
'/home/dex'.IO.chain.add('tmp').add('foo.txt').say;
my $d = now.DateTime;
say $d;
say $d.later(:1hour).later(:30minutes);
say $d.chain.later(:1hour, :30minutes);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment