3 package Data::Stream::Bulk::Array;
6 use namespace::clean -except => 'meta';
8 with qw(Data::Stream::Bulk) => { excludes => [qw/loaded filter list_cat/] };
13 writer => "_set_array",
14 clearer => "_clear_array",
15 predicate => "_has_array",
27 if ( my $array = $self->_array ) {
35 # squish several arrays into one
37 my ( $self, @rest ) = @_;
39 return $self unless @rest;
41 my @arrays = ( $self );
43 # fetch all adjacent arrays
44 push @arrays, shift @rest while @rest and $rest[0]->isa(__PACKAGE__);
48 push @cat, @$_ for map { $_->_array } @arrays;
49 return __PACKAGE__->new(
53 my $head = shift @rest;
54 return ( $self, $head->list_cat(@rest) );
59 my ( $self, $filter ) = @_;
60 local $_ = $self->next;
61 $self->_set_array( $filter->($_) );
67 __PACKAGE__->meta->make_immutable;
77 Data::Stream::Bulk::Array - L<Data::Stream::Bulk> wrapper for simple arrays.
81 return Data::Stream::Bulk::Array->new(
87 This implementation of the L<Data::Stream::Bulk> api wraps an array.
89 The use case is to keep the consumer of the data set implementation agnostic so
90 that it can deal with larger data sets if they are encountered, but still
91 retain most of the simplicity when the current data set easily fits in memory.
99 The array reference to wrap.
109 Returns the array reference on the first invocation, and nothing thereafter.
113 Returns true if C<next> has been called.
117 Squishes adjacent arrays into a new array.
121 Immediately applies C<$filter> to the internal array and returns C<$self>.