Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Useless use of given $_

  • Loading branch information...
commit 2b124a766e96e4c2c6065ccd0794c267a1e6d120 1 parent 97a7d39
@flussence authored
Showing with 19 additions and 16 deletions.
  1. +19 −16 lib/Indent.pm
View
35 lib/Indent.pm
@@ -13,23 +13,26 @@ multi indent(Str $str, $steps as Int where { $_ > 0 }) returns Str is export {
# We want to keep trailing \n so we have to .comb explicitly instead of .lines
return $str.comb(/:r ^^ \N* \n?/).map({
- given $_ {
- # Use the existing space character if they're all the same
- # (but tabs are done slightly differently)
- when /^(\t+) ([ \S .* | $ ])/ {
- $0 ~
- "\t" x ($steps div $tab) ~
- ' ' x ($steps mod $tab) ~
- $1
- }
- when /^(\h) $0* [ \S | $ ]/ {
- $0 x $steps ~ $_
- }
+ # Tab-only indentation gets special treatment
+ when /^(\t+) ([ \S .* | $ ])/ {
+ $0 ~
+ "\t" x ($steps div $tab) ~
+ ' ' x ($steps mod $tab) ~
+ $1
+ }
+
+ # Use the existing space character if they're all the same
+ when /^(\h) $0* [ \S | $ ]/ {
+ note 'prefix samespace join';
+ note "\$_ is '$_', \$0 is '{$0.Str}', \$steps is $steps";
+ warn '$0 is empty' unless $0.Str;
+ $0 x $steps ~ $_
+ }
- # Otherwise we just insert spaces after the existing leading space
- default {
- ($_ ~~ /^(\h*) (.*)$/).list.join(' ' x $steps)
- }
+ # Otherwise we just insert spaces after the existing leading space
+ default {
+ # XXX nom requires the .list here
+ ($_ ~~ /^(\h*) (.*)$/).list.join(' ' x $steps)
}
}).join;
}
Please sign in to comment.
Something went wrong with that request. Please try again.