| Collections documentation | Contained in the Collections distribution. |
Collections::Set - Easy to use iterator with unique elements
Version 0.01
use Collections::Set;
my $col = Collections::Set->new;
# Add new element
$col->add('some string');
$col->add('some string');
# Size will return 1 (One unique element)
print $col->size;
# Remove element
$col>remove('some string');
# Size will return 0
print $col->size;
Add $element as part of receiver's elements, if the element already exists it does nothing
$colection->add(1);
Add all $collection's element as part of receiver's elements, it adds elements that don't already exists in the collection
$colection->add_all($another_collection); ... or ... $collection->add_all(1,2,3); ... or ... $colection->add_all([1,2,3]);
Returns an Collections::Ordered with the same elements of this collection
my $col = $collection->to_ordered;
Mariano Wahlmann, <dichoso at gmail.com>
Please report any bugs or feature requests to dichoso at gmail.com.
I will be notified, and then you'll be notified of progress on your bug as I
make changes.
Copyright 2009 Mariano Wahlmann, all rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
| Collections documentation | Contained in the Collections distribution. |
package Collections::Set; use strict; use warnings; use base qw(Collections::Ordered); our $VERSION = '0.01';
sub add { my $self = shift; my $element = \(shift); if ( !$self->exists($$element)) { $self->SUPER::add($$element) } return $$element; }
sub add_all { my $self = shift; my @elements = $self->_parameter_to_array(@_); foreach (@elements) { $self->add($_); } }
sub to_ordered { my $self = shift; my $new = Collections::Ordered->new; $new->add_all($self); return $new; } 1; __END__