Data::...::Bulk(3pm)
π Data::...::Bulk β the manual, but make it a group chat π
okay bestie, sit down, hydrate, and let me tell you about Data::Stream::Bulk β it's the N at a time iteration API β¨ and honestly? she's iconic.
This is the <Data::...::Bulk(3pm)> page from the User Contributed Perl Documentation, and we're currently vibing on version 0.11 π
πΈ NAME πΈ
Data::Stream::Bulk β N at a time iteration API π¦
β¨ VERSION β¨
version 0.11</purl> β yes, that's the version, no cap.
π SYNOPSIS π
so like, here's the whole vibe in code, bestie:
# 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);
}
}
two whole ways to eat your data. pick your fighter π
π¦ DESCRIPTION π¦
okay so this module is literally trying to find the middle ground between one at a time and all at once processing of data sets. it's the "girl, why not both" of iteration. periodt.
the whole purpose here is to dodge the overhead of implementing an iterative api when that just isn't necessary β without breaking forward compatibility in case it becomes necessary later on. foresight? we love her. π
the API optimizes for when a data set typically fits in memory and is returned as an array β but listen, the consumer cannot assume that the data set is bounded. nope. don't do it. π
and the API is destructive on purpose, so that resultsets don't get leaked from improper usage. it's giving "we're doing this on purpose, for your own good." π
π API π
π Required Methods π
the API requires two methods to be implemented. just two. that's it. bestie behavior:
is_doneβ should return true if the stream is exhausted. and as long as this method returns a false value (not done),nextcould potentially return another block. so like, "am i done?" β answer honestly please. π«Άnextβ returns the next block. note thatnextis not guaranteed to return an array reference, even ifis_donereturned false prior to calling it. so don't go assuming things about her, okay? π
π Convenience Methods π
these are the little extras that make life cute:
itemsβ this method callsnextand dereferences the result if there are pending items. she does the unglamorous work so you don't have to β¨allβ force evaluation of the entire resultset. > warning bestie: for large data sets this might cause swap thrashing of various other undesired effects. use with caution. we are NOT playing. πcat @streamsβ concatenates this stream with @streams, returning a single stream. one stream to rule them all πlist_cat @tailβ returns a possibly cleaned up list of streams. it's used bycat. and it's overridden byData::Stream::Bulk::Array,Data::Stream::Bulk::CatandData::Stream::Bulk::Nilto implement some simple short circuiting. iconic crossover event πfilter $filterβ 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. glow-up but for data π¦chunk $chunk_sizeβ chunks the input stream so that each block returned bynextwill have at least $chunk_size items. little bite-sized pieces, yum πloadedβ should be overridden to return true if all the items are already realized (e.g. in the case ofData::Stream::Bulk::Array). returns false by default. and when it is true, callingallis supposed to be safe (memory usage should be in the same order of magnitude as stream's own usage). this is typically useful when transforming an array is easier than transforming a stream (e.g. optional duplicate filtering). lowkey a niche queen π
π CLASSES π
the whole friend group, let's meet them:
Data::Stream::Bulk::Arrayβ 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. she's simple, she's honest πData::Stream::Bulk::Callbackβ callback driven iteration. say less, she'll call you back πData::Stream::Bulk::Chunkedβ wrapper to return larger blocks from an existing stream. girl math but for data πData::Stream::Bulk::DBIβ bulk fetching of data from DBI statement handles.Data::Stream::Bulk::DBICβDBIx::Class::ResultSetiteration.Data::Stream::Bulk::FileHandleβ iterates over lines in a text file. line by line, one at a time, no drama πΈData::Stream::Bulk::Nilβ an empty result set. the void. nothing. ghosted π»Data::Stream::Bulk::Catβ a concatenation of several streams.Data::Stream::Bulk::Filterβ a filter wrapping a stream.
π SEE ALSO π
the extended universe, iykyk:
HOP::Stream,Iterator,Class::Iteratoretc for one by one iterationDBI,DBIx::Class::ResultSetPOE::FilterData::PageParallel::Iterator- <http://en.wikipedia.org/wiki/MapReduce>, LISP, and all that other kool aid π§
π TODO π
the "we'll get to it" list. manifesting β¨
- Sorted streams
- Add a hint for sorted streams (like
loadedbut as an attribute in the base role). - Introduce a
mergeoperation for merging of sorted streams. - Optimize
uniqueto make use of sorting hints for constant space uniquing.
- Add a hint for sorted streams (like
- More utility functions
- To assist in proccessing and creating streams.
- Coercion tables
Moose::Util::TypeConstraints
π VERSION CONTROL π
this module is maintained using git. you can get the latest version from <http://github.com/nothingmuch/data-stream-bulk/>. go forth and clone, bestie π«Ά
π AUTHOR π
Yuval Kogman <nothingmuch@woobling.org> β thank you for your service, king π
π COPYRIGHT AND LICENSE π
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. slay, legally π
and that's the whole page, bestie!! this little gem was brought to you by perl v5.32.0, dated 2021-01-01, from the Data::...::Bulk(3pm) manual in the User Contributed Perl Documentation. mwah π β¨ π¦ π
π¦ where this page comes from
- debian bookworm: libdata-stream-bulk-perl 0.11-1.1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libdata-stream-bulk-perl 0.11-1.1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu jammy: libdata-stream-bulk-perl 0.11-1.1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libdata-stream-bulk-perl 0.11-1.1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms