]> git.donarmstrong.com Git - debbugs.git/blobdiff - Debbugs/Collection.pm
allow apply to return > 1 object per collection member
[debbugs.git] / Debbugs / Collection.pm
index 350a03f777b427a0ea0bc139ab4d722788ce3ddd..6e3d49d95ed9e30f3caca34035cb527be0a89e52 100644 (file)
@@ -116,9 +116,15 @@ locally to each member object
 
 Returns the keys of the members of this collection joined
 
-=head2 $collection->apply({$_*2}) $collection->map({$_*2})
+=head2 $collection->apply({$_*2})
 
-Return the list of applying BLOCK to each member
+Return the list of applying BLOCK to each member; each member can return 0 or
+more results
+
+=head2 $collection->map({$_*2})
+
+Returns the list of applying BLOCK to each member; each member should return
+exactly one result
 
 =head2 $collection->sort({$a <=> $b})
 
@@ -137,12 +143,21 @@ has 'members' => (is => 'bare',
                              count => 'count',
                              _get_member => 'get',
                               grep => 'grep',
-                              apply => 'apply',
                               map => 'map',
                               sort => 'sort',
                             },
                 );
 
+sub apply {
+    my $self = shift;
+    my $block = shift;
+    my @r;
+    for ($self->members) {
+        push @r,$block->();
+    }
+    return @r;
+}
+
 sub members_ref {
     my $self = shift;
     return [$self->members];