Skip to content

Commit

Permalink
add 'cat' helper function
Browse files Browse the repository at this point in the history
  • Loading branch information
nothingmuch committed Sep 1, 2008
1 parent 123b6af commit 793bff1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
10 changes: 9 additions & 1 deletion lib/Data/Stream/Bulk/Util.pm
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ use Data::Stream::Bulk::Array;
use namespace::clean;

use Sub::Exporter -setup => {
exports => [qw(nil bulk)],
exports => [qw(nil bulk cat)],
};

sub nil () { Data::Stream::Bulk::Nil->new }

sub bulk (@) { return @_ ? Data::Stream::Bulk::Array->new( array => [ @_ ] ) : nil }

sub cat (@) { return @_ ? shift->cat(@_) : nil }

__PACKAGE__

__END__
Expand Down Expand Up @@ -61,6 +63,12 @@ Takes no arguments.
Creates a new L<Data::Stream::Bulk::Array> wrapping C<@items>.
=item cat @streams
Concatenate several streams together.
Returns C<nil> if no arguments are provided.
=back
=cut
Expand Down
9 changes: 8 additions & 1 deletion t/basic.t
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use Test::More 'no_plan';
use ok 'Data::Stream::Bulk::Nil';
use ok 'Data::Stream::Bulk::Array';
use ok 'Data::Stream::Bulk::Callback';
use ok 'Data::Stream::Bulk::Util' => qw(bulk nil);
use ok 'Data::Stream::Bulk::Util' => qw(bulk nil cat);

{
my $d = Data::Stream::Bulk::Nil->new;
Expand All @@ -21,6 +21,11 @@ use ok 'Data::Stream::Bulk::Util' => qw(bulk nil);
isa_ok( bulk(), "Data::Stream::Bulk::Nil", "bulk() helper with no items" );

isa_ok( nil->cat(nil), "Data::Stream::Bulk::Nil", "cating nil with nil results in nil" );

isa_ok( cat(), "Data::Stream::Bulk::Nil", "cat with no args returns nil" );

isa_ok( cat(nil), "Data::Stream::Bulk::Nil", "cat of nil is nil" );
isa_ok( cat(nil, nil, nil, nil), "Data::Stream::Bulk::Nil", "cat of several nil is nil" );
}

{
Expand All @@ -45,6 +50,8 @@ use ok 'Data::Stream::Bulk::Util' => qw(bulk nil);
isa_ok( $cat, "Data::Stream::Bulk::Array", "Array cat Array resuls in Array" );

is_deeply( $cat->next, \@array, "concatenated array into one block" );

is_deeply( [ cat(bulk(qw(foo bar)), bulk(qw(gorch baz)))->all ], \@array, "cat helper function" );
}

{
Expand Down

0 comments on commit 793bff1

Please sign in to comment.