Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: d61049ff52
Fetching contributors…

Cannot retrieve contributors at this time

40 lines (31 sloc) 0.934 kb
my class Duration is Cool does Real {
has Rat $.x = 0;
# A linear count of seconds.
method new($x) { self.bless: *, x => $x.Rat }
method Bridge(Duration:D:) { $!x.Num }
method Rat(Duration:D:) { $!x }
method Num(Duration:D:) { $!x }
multi method Str(Duration:D:) { ~$.x }
multi method perl(Duration:D:) { "Duration.new({$.x.perl})" }
}
multi sub prefix:<->(Duration:D $a) {
Duration.new: -$a.x;
}
multi sub infix:<+>(Duration:D $a, Real $b) {
Duration.new: $a.x + $b;
}
multi sub infix:<+>(Real $a, Duration:D $b) {
Duration.new: $a + $b.x;
}
multi sub infix:<+>(Duration:D $a, Duration:D $b) {
Duration.new: $a.x + $b.x;
}
multi sub infix:<->(Duration:D $a, Real $b) {
Duration.new: $a.x - $b;
}
multi sub infix:<->(Duration:D $a, Duration:D $b) {
Duration.new: $a.x - $b.x;
}
multi sub infix:<%>(Duration:D $a, Real $b) {
Duration.new: $a.x % $b
}
Jump to Line
Something went wrong with that request. Please try again.