]> git.donarmstrong.com Git - debbugs.git/blobdiff - Debbugs/Collection.pm
switch to compatibility level 12
[debbugs.git] / Debbugs / Collection.pm
index 552c0f391068b2ea3296f09982973b47c0460f14..6e3d49d95ed9e30f3caca34035cb527be0a89e52 100644 (file)
@@ -79,7 +79,8 @@ Returns a clone of this collection with the same universe as this collection
 
 =head2 $collection->limit(@member_keys)
 
-Returns a new collection limited to the list of member keys passed
+Returns a new collection limited to the list of member keys passed. Will add new
+members to the universe if they do not currently exist.
 
 =head2 $collection->add($member)
 
@@ -89,6 +90,10 @@ Add a member to this collection
 
 Add a member to this collection by key
 
+=head2 $collection->combine($collection2) or $collection + $collection2
+
+Combines the members of both collections together and returns the new collection
+
 =head2 $collection->get($member_key)
 
 Get member(s) by key, returning undef for keys which do not exist in the
@@ -111,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; each member can return 0 or
+more results
 
-Return the list of applying BLOCK to each member
+=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})
 
@@ -132,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];
@@ -295,6 +315,16 @@ sub add {
     return @members_added;
 }
 
+use overload '+' => "combine",
+    '""' => "CARP_TRACE";
+
+sub combine {
+    my $self = shift;
+    my $return = $self->clone;
+    $return->add($_->members) for @_;
+    return $return;
+}
+
 sub get {
     my $self = shift;
     my @res = map {$self->_get_member($_)}
@@ -309,7 +339,7 @@ sub member_key {
 
 sub keys_of_members {
     my $self = shift;
-    return $self->map(sub {$self->member_key($_[0])});
+    return $self->map(sub {$self->member_key($_)});
 }
 
 sub exists {