Home > Raku > my $*RAKU++ for -> **@ {};

my $*RAKU++ for -> **@ {};

As the title states, I made Raku bigger because lol context (that’s how the Synopsis is calling **@) makes supporting feed operators fairly easy. I wonder if Larry added this syntax to Signature with that goal in mind. With PR#5532 the following becomes possible.

<abc bbc cbc> ==> trans('a' => 'x', 'b' => 'i') ==> say();
# OUTPUT: (xic iic cic)

Armed with this I can make a script of mine a little simpler.

use MONKEY-TYPING;

augment class IO::Path {
method trans(|c) {
my $from = self.Str;
my $to = self.Str.trans(|c);

self.rename($to) unless $from eq $to
}
}

sub rename-whitespace(IO::Path $dir where *.d){
dir($dir).grep({ .d || .f && .rw })
==> trans("\c[space]" => "\c[no-break space]", "\c[apostrophe]" => "\c[prime]")
==> sub (*@a) { print '.' for @a}();

dir($dir).grep({ .d && .rw })».&?ROUTINE;
}

rename-whitespace('.'.IO);

put '';

I don’t like spaces in filenames, as they are often found with audio or video files. Having auto-complete friendly names makes using a CLI less bumpy. By teaching IO::Path to rename files by providing rules, as they are understood by Str.trans, I can use a feed operator to get the job done. (I wouldn’t be surprised to learn, that anonymous subs DWIM here to be emergent behaviour in Raku.)

Having another PR that adds .trans to IO::Path is tempting but requires more thought.

Categories: Raku