Skip to content

Commit

Permalink
refactor: Update Has 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 b761ce7 commit 082384b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
4 changes: 2 additions & 2 deletions spec/loophp/collection/CollectionSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -1075,13 +1075,13 @@ public function it_can_has(): void
->has(static function ($key, $value) {
return 'A';
})
->shouldReturn(true);
->shouldIterateAs([true]);

$this::fromIterable(range('A', 'C'))
->has(static function ($key, $value) {
return 'Z';
})
->shouldReturn(false);
->shouldIterateAs([false]);
}

public function it_can_head(): void
Expand Down
4 changes: 2 additions & 2 deletions src/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -517,9 +517,9 @@ public function groupBy(?callable $callable = null): CollectionInterface
return $this->pipe(GroupBy::of()($callable));
}

public function has(callable $callback): bool
public function has(callable $callback): CollectionInterface
{
return $this->pipe(Has::of()($callback))->getIterator()->current();
return $this->pipe(Has::of()($callback));
}

public function head(): CollectionInterface
Expand Down
8 changes: 6 additions & 2 deletions src/Contract/Operation/Hasable.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 @@ -12,7 +14,9 @@
interface Hasable
{
/**
* @psalm-param callable(TKey, T):(bool) $callback
* @psalm-param callable(TKey, T): bool $callback
*
* @psalm-return \loophp\collection\Contract\Collection<int, bool>
*/
public function has(callable $callback): bool;
public function has(callable $callback): Collection;
}

0 comments on commit 082384b

Please sign in to comment.