Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save AlexDaniel/429ed056c3791545824d2a1c139258fe to your computer and use it in GitHub Desktop.
Save AlexDaniel/429ed056c3791545824d2a1c139258fe to your computer and use it in GitHub Desktop.
multi sub infix:<+>(Unit $x, Unit $y) {
if (not $x.isSameUnit($y)) {die "Units do not match.";}
return Unit.new(magnitude => $x.magnitude + $y.magnitude, units => $x.units);
}
my $a = Units::Unit.new(magnitude => 1.2, units => ("m" => 1));
my $b = Units::Unit.new(magnitude => 5.0, units => ("m" => 1));
say $a + $b;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment