- Sponsor
-
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.
New Intersect and IntersectKeys operation.
- v17-8448fdd
- v16-a068dee
- v15-b0b4468
- v13-179c2a5
- v12-b8bfd5a
- v11-6ea3c47
- v10-ed5ef20
- v9-5321ebc
- v8-1bfd964
- v7-4e60bd1
- 7.6.1
- 7.6.0
- 7.5.2
- 7.5.1
- 7.5.0
- 7.4.0
- 7.3.0
- 7.2.1
- 7.2.0
- 7.1.2
- 7.1.1
- 7.1.0
- 7.0.0
- 6.0.3
- 6.0.2
- 6.0.1
- 6.0.0
- 5.1.0
- 5.0.0
- 4.1.0
- 4.0.7
- 4.0.6
- 4.0.5
- 4.0.4
- 4.0.3
- 4.0.2
- 4.0.1
- 4.0.0
- 3.4.3
- 3.4.2
- 3.4.1
- 3.4.0
- 3.3.5
- 3.3.4
- 3.3.3
- 3.3.2
- 3.3.1
- 3.3.0
- 3.2.0
- 3.1.1
- 3.1.0
- 3.0.5
- 3.0.4
- 3.0.3
- 3.0.2
- 3.0.1
- 3.0.0
- 2.7.4
- 2.7.3
- 2.7.2
- 2.7.1
- 2.7.0
- 2.6.3
- 2.6.2
- 2.6.1
- 2.6.0
- 2.5.5
- 2.5.4
- 2.5.3
- 2.5.2
- 2.5.1
- 2.5.0
- 2.4.0
- 2.3.5
- 2.3.4
- 2.3.3
- 2.3.2
- 2.3.1
- 2.3.0
- 2.2.0
- 2.1.0
- 2.0.5
- 2.0.4
- 2.0.3
- 2.0.2
- 2.0.1
- 2.0.0
Showing
7 changed files
with
148 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace loophp\collection\Contract\Operation; | ||
|
||
use loophp\collection\Contract\Base; | ||
|
||
interface Intersectable | ||
{ | ||
/** | ||
* @param mixed ...$values | ||
* | ||
* @return \loophp\collection\Base|\loophp\collection\Contract\Collection | ||
*/ | ||
public function intersect(...$values): Base; | ||
} |
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,17 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace loophp\collection\Contract\Operation; | ||
|
||
use loophp\collection\Contract\Base; | ||
|
||
interface Intersectkeysable | ||
{ | ||
/** | ||
* @param mixed ...$values | ||
* | ||
* @return \loophp\collection\Base|\loophp\collection\Contract\Collection | ||
*/ | ||
public function intersectKeys(...$values): Base; | ||
} |
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,37 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace loophp\collection\Operation; | ||
|
||
use Closure; | ||
use Generator; | ||
use loophp\collection\Contract\Operation; | ||
|
||
use function in_array; | ||
|
||
final class Intersect extends AbstractOperation implements Operation | ||
{ | ||
/** | ||
* @param mixed ...$values | ||
*/ | ||
public function __construct(...$values) | ||
{ | ||
$this->storage['values'] = $values; | ||
} | ||
|
||
public function __invoke(): Closure | ||
{ | ||
return | ||
/** | ||
* @param array<int, mixed> $values | ||
*/ | ||
static function (iterable $collection, $values): Generator { | ||
foreach ($collection as $key => $value) { | ||
if (true === in_array($value, $values, true)) { | ||
yield $key => $value; | ||
} | ||
} | ||
}; | ||
} | ||
} |
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,37 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace loophp\collection\Operation; | ||
|
||
use Closure; | ||
use Generator; | ||
use loophp\collection\Contract\Operation; | ||
|
||
use function in_array; | ||
|
||
final class IntersectKeys extends AbstractOperation implements Operation | ||
{ | ||
/** | ||
* @param mixed ...$values | ||
*/ | ||
public function __construct(...$values) | ||
{ | ||
$this->storage['values'] = $values; | ||
} | ||
|
||
public function __invoke(): Closure | ||
{ | ||
return | ||
/** | ||
* @param array<int, mixed> $values | ||
*/ | ||
static function (iterable $collection, $values): Generator { | ||
foreach ($collection as $key => $value) { | ||
if (true === in_array($key, $values, true)) { | ||
yield $key => $value; | ||
} | ||
} | ||
}; | ||
} | ||
} |