Patrick R. Michaud wrote: > On Sat, Mar 07, 2009 at 09:50:02PM -0800, Vasily Chekalkin wrote: >> +our List multi min(*...@values) { >> + my $by = @values[0] ~~ Code ?? shift @values !! sub { $^a cmp $^b }; >> + @values.min($by); >> +} > > This doesn't match the spec -- the $by parameter is required. > At any rate, the first argument should not be explicitly checked > for being a Code object -- if we do this it should be via a multi > signature.
I've fixed that, and corrected the spec tests accordingly. > Yes, the PIR code was "cheating" in this respect, but I don't > want to blindly copy our cheats from PIR into the setting without > subjecting them to another review. > >> + # RT #63700 - parse failed on &infix:<cmp> >> + our Array multi method min( $values: Code $by = sub { $^a cmp $^b } ) { >> + my @list = $values.list; >> + return +Inf unless @list.elems; >> + my $res = @list.shift; >> + for @list -> $x { >> + if (&$by($res, $x) > 0) { >> + $res = $x; >> + } >> + } >> + $res; >> + }; >> } > > Why are C<min> and C<max> specced as returning C<Array> and C<List>? > Shouldn't they just return the single element that is the minimum > or maximum from the list? I agree, so I removed the non-sense return types from the specs. Cheers, Moritz