Skip to content

Commit

Permalink
Merge pull request #305 from gfldex/master
Browse files Browse the repository at this point in the history
add example for hyperoperator with user defined operator
  • Loading branch information
gfldex committed Jan 1, 2016
2 parents 09b4ed9 + 3bd21c4 commit a869aa9
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions doc/Language/operators.pod
Expand Up @@ -223,6 +223,32 @@ C<%outer »+» %inner;> only keys of %inner that exist in %outer will occur in
my %inner = 1,2 Z=> <x z>;
say %outer «~» %inner; # {"1" => "ax", "2" => "bz"}
Hyper operators can take user defined operators as its operator argument.
sub pretty-file-site (Int $size --> Str) {
# rounding version of infix:</>(Int,Int)
sub infix:<r/>(Int \i1, Int \i2) {
round(i1 / i2, 0.1)
}
# we build a vector of fractions of $size and zip that with the fitting prefix
for $size «[r/]« (2**60, 2**50, 2**40, 2**30, 2**20, 2**10)
Z <EB PB TB GB MB KB> -> [\v,\suffix] {
# starting with the biggest suffix, we take the first that is 0.5 of that suffix or bigger
return v ~ ' ' ~ suffix if v > 0.4
}
# this be smaller or equal then 0.4 KB
return $size.Str;
}
for 60, 50, 40, 30, 20, 10 -> $test {
my &a = { (2 ** $test) * (1/4, 1/2, 1, 10, 100).pick * (1..10).pick };
print pretty-file-site(a.Int) xx 2, ' ';
}
# OUTPUT: «10 EB 4 EB 2 PB 5 PB 0.5 PB 4 TB 300 GB 4.5 GB 50 MB 200 MB 9 KB 0.6 MB»
=head2 Reduction Operators
Reduction operators apply any infix operator, surrounded by C<[> and C<]>,
Expand Down

0 comments on commit a869aa9

Please sign in to comment.