-
-
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.
This should fix #313
- Loading branch information
Showing
4 changed files
with
93 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace loophp\collection\Contract\Operation; | ||
|
||
use loophp\collection\Contract\Collection; | ||
|
||
/** | ||
* @template TKey | ||
* @template T | ||
*/ | ||
interface Plusable | ||
{ | ||
/** | ||
* TODO - Plus items. | ||
* | ||
* @see https://loophp-collection.readthedocs.io/en/stable/pages/api.html#plus | ||
* | ||
* @template UKey | ||
* @template U | ||
* | ||
* @param iterable<UKey, U> $items | ||
* | ||
* @return Collection<int|TKey|UKey, T|U> | ||
*/ | ||
public function plus(iterable $items): 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,53 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace loophp\collection\Operation; | ||
|
||
use Closure; | ||
use Generator; | ||
use loophp\iterators\ConcatIterableAggregate; | ||
|
||
/** | ||
* @immutable | ||
* | ||
* @template TKey | ||
* @template T | ||
*/ | ||
final class Plus extends AbstractOperation | ||
{ | ||
/** | ||
* @template UKey | ||
* @template U | ||
* | ||
* @return Closure(iterable<UKey, U>): Closure(iterable<TKey, T>): iterable<int|TKey|UKey, T|U> | ||
*/ | ||
public function __invoke(): Closure | ||
{ | ||
$comparatorCallback = | ||
/** | ||
* @param T $left | ||
* | ||
* @return Closure(T): bool | ||
*/ | ||
static fn (mixed $left): Closure => | ||
/** | ||
* @param T $right | ||
*/ | ||
static fn (mixed $right): bool => $left === $right; | ||
|
||
return | ||
/** | ||
* @param iterable<UKey, U> $items | ||
* | ||
* @return Closure(iterable<TKey, T>): iterable<int|TKey|UKey, T|U> | ||
*/ | ||
static fn (iterable $items): Closure => | ||
/** | ||
* @param iterable<TKey, T> $iterable | ||
* | ||
* @return Generator<int|TKey|UKey, T|U> | ||
*/ | ||
static fn (iterable $iterable): Generator => yield from (new Distinct())()($comparatorCallback)(static fn (mixed $value, mixed $key): mixed => $key)(new ConcatIterableAggregate([$iterable, $items])); | ||
} | ||
} |