N at a time iteration api
version 0.11
# get a bulk stream from somewere my $s = Data::Stream::Bulk::Foo->new( ... ); # can be used like this: until ( $s->is_done ) { foreach my $item ( $s->items ) { process($item); } } # or like this: while( my $block = $s->next ) { foreach my $item ( @$block ) { process($item); } }
This module tries to find middle ground between one at a time and all at once processing of data sets.
The purpose of this module is to avoid the overhead of implementing an iterative api when this isn't necessary, without breaking forward compatibility in case that becomes necessary later on.
The \s-1API\s0 optimizes for when a data set typically fits in memory and is returned as an array, but the consumer cannot assume that the data set is bounded.
The \s-1API\s0 is destructive in order to minimize the chance that resultsets are leaked due to improper usage.
The \s-1API\s0 requires two methods to be implemented:
Should return true if the stream is exhausted. As long as this method returns a false value (not done) \*(C`next\*(C' could potentially return another block.
Returns the next block. Note that \*(C`next\*(C' is not guaranteed to return an array reference, even if \*(C`is_done\*(C' returned false prior to calling it.
This method calls \*(C`next\*(C' and dereferences the result if there are pending items.
Force evaluation of the entire resultset. Note that for large data sets this might cause swap thrashing of various other undesired effects. Use with caution. Concatenates this stream with @streams, returning a single stream. Returns a possibly cleaned up list of streams. Used by \*(C`cat\*(C'. Overridden by Data::Stream::Bulk::Array, Data::Stream::Bulk::Cat and Data::Stream::Bulk::Nil to implement some simple short circuiting. Applies a per-block block filter to the stream. Returns a possibly new stream with the filtering layered. $filter is invoked once per block and should return an array reference to the filtered block. Chunks the input stream so that each block returned by \*(C`next\*(C' will have at least $chunk_size items.
Should be overridden to return true if all the items are already realized (e.g. in the case of Data::Stream::Bulk::Array). Returns false by default. When true calling \*(C`all\*(C' is supposed to be safe (memory usage should be in the same order of magnitude as stream's own usage). This is typically useful when tranforming an array is easier than transorming a stream (e.g. optional duplicate filtering).
This class is not a stream at all, but just one block. When the data set easily fits in memory this class can be used, while retaining forward compatibility with larger data sets.
Callback driven iteration.
Wrapper to return larger blocks from an existing stream.
Bulk fetching of data from \s-1DBI\s0 statement handles.
DBIx::Class::ResultSet iteration.
Iterates over lines in a text file.
An empty result set.
A concatenation of several streams.
A filter wrapping a stream.
HOP::Stream, Iterator, Class::Iterator etc for one by one iteration
\s-1DBI\s0, DBIx::Class::ResultSet
POE::Filter
Data::Page
Parallel::Iterator
<http://en.wikipedia.org/wiki/MapReduce>, \s-1LISP\s0, and all that other kool aid
Add a hint for sorted streams (like \*(C`loaded\*(C' but as an attribute in the base role). Introduce a \*(C`merge\*(C' operation for merging of sorted streams. Optimize \*(C`unique\*(C' to make use of sorting hints for constant space uniquing.
To assist in proccessing and creating streams.
Moose::Util::TypeConstraints
This module is maintained using git. You can get the latest version from http://github.com/nothingmuch/data-stream-bulk/ <http://github.com/nothingmuch/data-stream-bulk/>.
Yuval Kogman <[email protected]>
This software is copyright (c) 2012 by Yuval Kogman.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.