-
Notifications
You must be signed in to change notification settings - Fork 1
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
3 changed files
with
202 additions
and
58 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Maxonfjvipon\ElegantElephant\Any; | ||
|
||
use Maxonfjvipon\ElegantElephant\Any; | ||
use Maxonfjvipon\ElegantElephant\Arr; | ||
|
||
use function Maxonfjvipon\ElegantElephant\reduced; | ||
|
||
/** | ||
* Array reduced. | ||
*/ | ||
final class Reduced implements Any | ||
{ | ||
/** | ||
* @var callable $callback | ||
*/ | ||
private $callback; | ||
|
||
/** | ||
* @param array<mixed>|Arr $arr | ||
* @param callable $callback | ||
* @param mixed $init | ||
* @param bool $ensureInit | ||
*/ | ||
public function __construct( | ||
private array|Arr $arr, | ||
callable $callback, | ||
private mixed $init, | ||
private bool $ensureInit = false | ||
) { | ||
$this->callback = $callback; | ||
} | ||
|
||
public function value(): mixed | ||
{ | ||
return reduced($this->arr, $this->callback, $this->init, $this->ensureInit); | ||
} | ||
} |
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
Oops, something went wrong.