3 package Data::Stream::Bulk::Util;
8 use Data::Stream::Bulk::Nil;
9 use Data::Stream::Bulk::Array;
11 use Scalar::Util qw(refaddr);
15 use Sub::Exporter -setup => {
16 exports => [qw(nil bulk cat filter unique)],
19 # use constant nil => Data::Stream::Bulk::Nil->new;
20 sub nil () { Data::Stream::Bulk::Nil->new }
22 sub bulk (@) { return @_ ? Data::Stream::Bulk::Array->new( array => [ @_ ] ) : nil }
24 sub cat (@) { return @_ ? shift->cat(@_) : nil }
27 my ( $filter, $stream ) = @_;
28 $stream->filter($filter);
33 shift->filter(sub { [ grep { !$seen{ref($_) ? refaddr($_) : $_}++ } @$_ ] }); # FIXME Hash::Util::FieldHash::Compat::id()?
44 Data::Stream::Bulk::Util - Utility functions for L<Data::Stream::Bulk>
48 use Data::Stream::Bulk::Util qw(array);
52 # Wrap a list in L<Data::Stream::Bulk::Array>
53 return bulk(qw(foo bar gorch baz));
55 # return an empty resultset
60 This module exports convenience functions for use with L<Data::Stream::Bulk>.
64 L<Sub::Exporter> is used to create the C<import> routine, and all of its
65 aliasing/currying goodness is of course supported.
71 Creates a new L<Data::Stream::Bulk::Nil> object.
77 Creates a new L<Data::Stream::Bulk::Array> wrapping C<@items>.
81 Concatenate several streams together.
83 Returns C<nil> if no arguments are provided.
85 =item filter { ... } $stream
87 Calls C<filter> on $stream with the provided filter.
91 Filter the stream to remove duplicates.
93 Note that memory use may potentially scale to O(k) where k is the number of
94 distinct items, because this is implemented in terms of a seen hash.
96 In the future this will be optimized to be iterative for sorted streams.
98 References are keyed by their refaddr (see L<Hash::Util::FieldHash/id>).