Created
January 25, 2021 21:30
-
-
Save gfldex/9e45f51cdb346e5e6e026fe8bdd0e5bc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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