# New Ticket Created by Vasily Chekalkin # Please include the string: [perl #55482] # in the subject line of all future correspondence about this issue. # <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=55482 >
Hello. There is implementation of List.min and List.max -- Bacek
diff --git a/languages/perl6/src/classes/List.pir b/languages/perl6/src/classes/List.pir index b9b5107..3b6fe2a 100644 --- a/languages/perl6/src/classes/List.pir +++ b/languages/perl6/src/classes/List.pir @@ -684,6 +686,107 @@ .end +=item min() + +Return minimum element in list + +=cut + +.sub 'min' :method :multi('ResizablePMCArray') + .param pmc by :optional + .param int has_by :opt_flag + .local pmc elem, res, iter + + if has_by goto start + by = get_hll_global 'infix:<=>' + start: + iter = self.'iterator'() + if iter goto do_work + res = new 'Failure' + goto done + + do_work: + res = shift iter + loop: + unless iter goto done + elem = shift iter + $I0 = by(elem, res) + unless $I0 < 0 goto loop + res = elem + goto loop + + done: + .return(res) +.end + +.namespace [] +.sub 'min' :multi(Closure) + .param pmc by + .param pmc values :slurpy + $P0 = values.'min'(by) + .return ($P0) +.end + +.sub 'min' :multi() + .param pmc values :slurpy + .local pmc by + by = get_hll_global 'infix:<=>' + $P0 = values.'min'(by) + .return ($P0) +.end + + +.namespace ['List'] +=item max() + +Return maximum element in list + +=cut + +.sub 'max' :method :multi('ResizablePMCArray') + .param pmc by :optional + .param int has_by :opt_flag + .local pmc elem, res, iter + + if has_by goto start + by = get_hll_global 'infix:<=>' + start: + iter = self.'iterator'() + if iter goto do_work + res = new 'Failure' + goto done + + do_work: + res = shift iter + loop: + unless iter goto done + elem = shift iter + $I0 = by(elem, res) + unless $I0 > 0 goto loop + res = elem + goto loop + + done: + .return(res) +.end + +.namespace [] +.sub 'max' :multi(Closure) + .param pmc by + .param pmc values :slurpy + $P0 = values.'max'(by) + .return ($P0) +.end + +.sub 'max' :multi() + .param pmc values :slurpy + .local pmc by + by = get_hll_global 'infix:<=>' + $P0 = values.'max'(by) + .return ($P0) +.end + + =back =head1 Functions