-
-
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
7 changed files
with
162 additions
and
3 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
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\Base; | ||
|
||
/** | ||
* Interface Transposeable. | ||
*/ | ||
interface Transposeable | ||
{ | ||
/** | ||
* Matrix transposition. | ||
* | ||
* @return \loophp\collection\Base<mixed>|\loophp\collection\Contract\Collection<mixed> | ||
*/ | ||
public function transpose(): 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,35 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace loophp\collection\Operation; | ||
|
||
use Closure; | ||
use Generator; | ||
use loophp\collection\Contract\Operation; | ||
use loophp\collection\Iterator\IterableIterator; | ||
use MultipleIterator; | ||
|
||
/** | ||
* Class Transpose. | ||
*/ | ||
final class Transpose implements Operation | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function __invoke(): Closure | ||
{ | ||
return static function (iterable $collection): Generator { | ||
$mit = new MultipleIterator(MultipleIterator::MIT_NEED_ANY); | ||
|
||
foreach ($collection as $collectionItem) { | ||
$mit->attachIterator(new IterableIterator($collectionItem)); | ||
} | ||
|
||
foreach ($mit as $key => $value) { | ||
yield current($key) => $value; | ||
} | ||
}; | ||
} | ||
} |