-
-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
138 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace loophp\collection\Contract\Operation; | ||
|
||
use loophp\collection\Contract\Collection; | ||
|
||
/** | ||
* @psalm-template TKey | ||
* @psalm-template TKey of array-key | ||
* @psalm-template T of bool | ||
*/ | ||
interface Everyable | ||
{ | ||
/** | ||
* @psalm-return \loophp\collection\Contract\Collection<TKey, bool> | ||
*/ | ||
public function every(callable $callback): Collection; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace loophp\collection\Operation; | ||
|
||
use Closure; | ||
use Generator; | ||
use Iterator; | ||
|
||
/** | ||
* @psalm-template TKey | ||
* @psalm-template TKey of array-key | ||
* @psalm-template T | ||
* | ||
* phpcs:disable Generic.Files.LineLength.TooLong | ||
*/ | ||
final class Every extends AbstractOperation | ||
{ | ||
/** | ||
* @psalm-return Closure((callable(T, TKey, Iterator<TKey, T>): bool)): Closure(Iterator<TKey, T>): Generator<TKey, bool> | ||
*/ | ||
public function __invoke(): Closure | ||
{ | ||
return | ||
/** | ||
* @psalm-return Closure(Iterator<TKey, T>): Generator<TKey, bool> | ||
*/ | ||
static function (callable $callback): Closure { | ||
$callbackBuilder = | ||
/** | ||
* @psalm-param callable(T, TKey, Iterator<TKey, T>): bool $callback | ||
*/ | ||
static function (callable $callback): Closure { | ||
return | ||
/** | ||
* @param mixed $carry | ||
* @psalm-param T $carry | ||
* | ||
* @param mixed $value | ||
* @psalm-param T $value | ||
* | ||
* @param mixed $key | ||
* @psalm-param TKey $key | ||
* @psalm-param Iterator<TKey, T> $iterator | ||
*/ | ||
static function ($carry, $value, $key, Iterator $iterator) use ($callback): bool { | ||
return $callback($value, $key, $iterator); | ||
}; | ||
}; | ||
|
||
/** @psalm-var Closure(Iterator<TKey, T>): Generator<TKey, bool> $foldLeft */ | ||
$foldLeft = FoldLeft::of()($callbackBuilder($callback))(true); | ||
|
||
// Point free style. | ||
return $foldLeft; | ||
}; | ||
} | ||
} |