Skip to content

Commit

Permalink
improved Mojo::Collection to allow join without arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Nov 17, 2013
1 parent 0de0c92 commit c07f904
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 1 deletion.
1 change: 1 addition & 0 deletions Changes
@@ -1,6 +1,7 @@

4.58 2013-11-17
- Improved IIS and WebSphere compatibility of Mojo::Message::Request.
- Improved Mojo::Collection to allow join without arguments.
- Improved Mojo::DOM::HTML performance.
- Fixed recursion bug in Mojo::Reactor::EV where timers could run more than
once.
Expand Down
3 changes: 2 additions & 1 deletion lib/Mojo/Collection.pm
Expand Up @@ -58,7 +58,7 @@ sub grep {
return $self->new(grep { $_ =~ $cb } @$self);
}

sub join { Mojo::ByteStream->new(join $_[1], map({"$_"} @{$_[0]})) }
sub join { Mojo::ByteStream->new(join $_[1] // '', map({"$_"} @{$_[0]})) }

sub map {
my ($self, $cb) = @_;
Expand Down Expand Up @@ -202,6 +202,7 @@ argument passed to the callback and is also available as C<$_>.
=head2 join
my $stream = $collection->join;
my $stream = $collection->join("\n");
Turn collection into L<Mojo::ByteStream>.
Expand Down
1 change: 1 addition & 0 deletions t/mojo/collection.t
Expand Up @@ -65,6 +65,7 @@ is_deeply [$collection->grep(sub { $_ > 9 })->each], [], 'no elements';

# join
$collection = c(1, 2, 3);
is $collection->join, '123', 'right result';
is $collection->join(''), '123', 'right result';
is $collection->join('---'), '1---2---3', 'right result';
is $collection->join("\n"), "1\n2\n3", 'right result';
Expand Down

0 comments on commit c07f904

Please sign in to comment.