Next Program Repair Shop 73

Higher-order functions

        sub group_items {
          my ($comparator, @items) = @_;
          my @groups;
          while (my $first = shift @items) {
            my @group = ($first);
            my @ungrouped;
            for my $next (@items) {
              if ($comparator->($first, $next) == 0) {
                push @group, $next;      
              } else {
                push @ungrouped, @next;
              }
            }
            push @groups, \@group;
            @items = @ungrouped;          
          }          
          return @groups;
        }

Next Copyright © 2006 M. J. Dominus