Skip to content

Commit

Permalink
refactor: Update Get 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 a99e72a commit b761ce7
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
4 changes: 2 additions & 2 deletions spec/loophp/collection/CollectionSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -887,11 +887,11 @@ public function it_can_get(): void
{
$this::fromIterable(range('A', 'E'))
->get(4)
->shouldReturn('E');
->shouldIterateAs(['E']);

$this::fromIterable(range('A', 'E'))
->get('unexistent key', 'default')
->shouldReturn('default');
->shouldIterateAs(['default']);
}

public function it_can_get_an_iterator(): void
Expand Down
4 changes: 2 additions & 2 deletions src/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -497,9 +497,9 @@ static function (string $string, string $delimiter): Generator {
);
}

public function get($key, $default = null)
public function get($key, $default = null): CollectionInterface
{
return $this->pipe(Get::of()($key)($default))->getIterator()->current();
return $this->pipe(Get::of()($key)($default));
}

public function getIterator(): ClosureIterator
Expand Down
7 changes: 4 additions & 3 deletions src/Contract/Operation/Getable.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

namespace loophp\collection\Contract\Operation;

use loophp\collection\Contract\Collection;

/**
* @psalm-template TKey
* @psalm-template TKey of array-key
Expand All @@ -20,8 +22,7 @@ interface Getable
* @param mixed $default
* @psalm-param T|null $default
*
* @return mixed
* @psalm-return T|null
* @psalm-return \loophp\collection\Contract\Collection<TKey, T|null>
*/
public function get($key, $default = null);
public function get($key, $default = null): Collection;
}

0 comments on commit b761ce7

Please sign in to comment.