Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Update Partition operation. * Update Span operation. * Update tests. * Update documentation. * Update documentation * Improve tests * SA Check: Span * SA Check: Partition Co-authored-by: AlexandruGG <alex.gidei@goodlord.co>
- Loading branch information
Showing
11 changed files
with
345 additions
and
119 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,39 @@ | ||
<?php | ||
|
||
/** | ||
* For the full copyright and license information, please view | ||
* the LICENSE file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App; | ||
|
||
use ArrayIterator; | ||
use loophp\collection\Collection; | ||
use loophp\collection\Operation\Span; | ||
|
||
include __DIR__ . '/../../../../vendor/autoload.php'; | ||
|
||
$input = range(1, 10); | ||
|
||
// Example 1 -> Retrieve the left and right groups | ||
[$first, $last] = Collection::fromIterable($input) | ||
->span(static fn ($x): bool => 4 > $x) | ||
->all(); | ||
|
||
print_r($first->all()); // [1, 2, 3] | ||
print_r($last->all()); // [4, 5, 6, 7, 8, 9, 10] | ||
|
||
// Example 2 -> Retrieve the second group only | ||
$last = Collection::fromIterable($input) | ||
->span(static fn ($x): bool => 4 > $x) | ||
->last() | ||
->current(); | ||
|
||
print_r($last->all()); // [4, 5, 6, 7, 8, 9, 10] | ||
|
||
// Example 3 -> Use Span operation separately | ||
[$left] = iterator_to_array(Span::of()(static fn ($x): bool => 4 > $x)(new ArrayIterator($input))); | ||
|
||
print_r(iterator_to_array($left)); // [1, 2, 3] |
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
Oops, something went wrong.