=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)
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
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})
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];
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($_)}
sub keys_of_members {
my $self = shift;
- return $self->map(sub {$self->member_key($_[0])});
+ return $self->map(sub {$self->member_key($_)});
}
sub exists {