perl set object
Matt S Trout [Wed, 20 Jan 2010 11:04:22 +0000 (11:04 +0000)]
lib/Data/Perl/Collection/Set.pm [new file with mode: 0644]

diff --git a/lib/Data/Perl/Collection/Set.pm b/lib/Data/Perl/Collection/Set.pm
new file mode 100644 (file)
index 0000000..7415b9d
--- /dev/null
@@ -0,0 +1,21 @@
+package Data::Perl::Collection::Set;
+
+use Moose;
+use Method::Signatures::Simple;
+use Data::Perl::Stream::Array;
+
+has '_members' => (is => 'ro', required => 1, init_arg => 'members');
+
+method map ($fun) {
+  (ref $self)->new(
+    members => [ map $fun->($_), @{$self->_members} ]
+  )
+}
+
+method as_stream {
+  Data::Perl::Stream::Array->new(array => [ @{$self->_members} ])
+}
+
+__PACKAGE__->meta->make_immutable;
+
+1;