Skip to content

Commit

Permalink
refactor: Update Implode operation.
Browse files Browse the repository at this point in the history
BREAKING CHANGE: yes
  • Loading branch information
drupol committed Oct 7, 2020
1 parent 082384b commit 4cedd34
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
10 changes: 5 additions & 5 deletions spec/loophp/collection/CollectionSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,8 @@ public function it_can_be_constructed_from_a_stream(): void

$stream = fopen('data://text/plain,' . $string, 'rb');
$this::fromResource($stream)
->implode('')
->shouldReturn($string);
->implode()
->shouldIterateAs([55 => $string]);
}

public function it_can_be_constructed_from_array(): void
Expand Down Expand Up @@ -1126,11 +1126,11 @@ public function it_can_implode(): void
{
$this::fromIterable(range('A', 'C'))
->implode('-')
->shouldReturn('A-B-C');
->shouldIterateAs([2 => 'A-B-C']);

$this::fromIterable(range('A', 'C'))
->implode()
->shouldReturn('ABC');
->shouldIterateAs([2 => 'ABC']);
}

public function it_can_init(): void
Expand Down Expand Up @@ -2621,7 +2621,7 @@ public function it_can_use_with(): void
->last()
->unwrap()
->implode()
->shouldReturn('indent_size = 4');
->shouldIterateAs([14 => 'indent_size = 4']);

$stream = fopen(__DIR__ . '/../../fixtures/sample.txt', 'rb');

Expand Down
4 changes: 2 additions & 2 deletions src/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -546,9 +546,9 @@ static function ($value, $key) {
return $this->pipe(IfThenElse::of()($condition)($then)($else));
}

public function implode(string $glue = ''): string
public function implode(string $glue = ''): CollectionInterface
{
return $this->pipe(Implode::of()($glue))->getIterator()->current();
return $this->pipe(Implode::of()($glue));
}

public function init(): CollectionInterface
Expand Down
12 changes: 11 additions & 1 deletion src/Contract/Operation/Implodeable.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,17 @@

namespace loophp\collection\Contract\Operation;

use loophp\collection\Contract\Collection;

/**
* @psalm-template TKey
* @psalm-template TKey of array-key
* @psalm-template T
*/
interface Implodeable
{
public function implode(string $glue = ''): string;
/**
* @psalm-return \loophp\collection\Contract\Collection<int, string>
*/
public function implode(string $glue = ''): Collection;
}

0 comments on commit 4cedd34

Please sign in to comment.