Skip to content

Commit 7158236

Browse files
committed
First commit!
0 parents  commit 7158236

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+3027
-0
lines changed

.docheader

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/**
2+
* This file is part of php-fast-forward/iterators.
3+
*
4+
* This source file is subject to the license that is bundled
5+
* with this source code in the file LICENSE.
6+
*
7+
* @link https://github.com/php-fast-forward/iterators
8+
* @copyright Copyright (c) 2025-%year% Felipe Sayão Lobato Abreu <[email protected]>
9+
* @license https://opensource.org/licenses/MIT MIT License
10+
*/

.editorconfig

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
root = true
2+
3+
[*]
4+
indent_style = space
5+
indent_size = 4
6+
end_of_line = lf
7+
charset = utf-8
8+
trim_trailing_whitespace = true
9+
insert_final_newline = true
10+
11+
[*.md]
12+
trim_trailing_whitespace = false

.gitattributes

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
* text=auto
2+
/.github/ export-ignore
3+
/tests/ export-ignore
4+
/.docheader export-ignore
5+
/.dockerignore export-ignore
6+
/.editorconfig export-ignore
7+
/.gitattributes export-ignore
8+
/.gitignore export-ignore
9+
/.php-cs-fixer.php export-ignore
10+
/docker-compose export-ignore
11+
/Dockerfile export-ignore
12+
/infection.json5 export-ignore
13+
/phpunit.xml export-ignore

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.idea/
2+
public/
3+
vendor/
4+
composer.lock
5+
*.cache

.php-cs-fixer.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* This file is part of php-fast-forward/iterators.
7+
*
8+
* This source file is subject to the license that is bundled
9+
* with this source code in the file LICENSE.
10+
*
11+
* @link https://github.com/php-fast-forward/iterators
12+
* @copyright Copyright (c) 2025 Felipe Sayão Lobato Abreu <[email protected]>
13+
* @license https://opensource.org/licenses/MIT MIT License
14+
*/
15+
16+
use CoiSA\PhpCsFixer\PhpCsFixer;
17+
18+
$paths = [
19+
__FILE__,
20+
__DIR__,
21+
];
22+
23+
$header = file_get_contents(__DIR__ . '/.docheader');
24+
25+
return PhpCsFixer::create($paths, $header);

LICENSE

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Copyright (c) 2025 Felipe Sayão Lobato Abreu
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy
4+
of this software and associated documentation files (the "Software"), to deal
5+
in the Software without restriction, including without limitation the rights
6+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
copies of the Software, and to permit persons to whom the Software is furnished
8+
to do so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in all
11+
copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19+
THE SOFTWARE.

composer.json

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
{
2+
"name": "fast-forward/iterators",
3+
"description": "A robust and optimized library for advanced PHP Iterators.",
4+
"license": "MIT",
5+
"type": "library",
6+
"keywords": [
7+
"php",
8+
"iterators",
9+
"iterator utilities",
10+
"iterator aggregate",
11+
"iterator iterator",
12+
"fast-forward"
13+
],
14+
"authors": [
15+
{
16+
"name": "Felipe Sayão Lobato Abreu",
17+
"email": "[email protected]"
18+
}
19+
],
20+
"homepage": "https://github.com/php-fast-forward",
21+
"support": {
22+
"issues": "https://github.com/php-fast-forward/iterators/issues",
23+
"source": "https://github.com/php-fast-forward/iterators"
24+
},
25+
"require": {
26+
"php": "^7.4 || ^8.0"
27+
},
28+
"require-dev": {
29+
"coisa/php-cs-fixer": "^2.1",
30+
"infection/infection": "^0.29",
31+
"phpstan/phpstan": "^2.1",
32+
"phpunit/phpunit": "^9.6 || ^10.5 || ^11.5"
33+
},
34+
"minimum-stability": "stable",
35+
"autoload": {
36+
"psr-4": {
37+
"FastForward\\Iterator\\": "src/"
38+
},
39+
"files": [
40+
"src/functions.php"
41+
]
42+
},
43+
"config": {
44+
"allow-plugins": {
45+
"infection/extension-installer": true
46+
},
47+
"sort-packages": true
48+
},
49+
"extra": {
50+
"branch-alias": {
51+
"dev-main": "1.x-dev"
52+
}
53+
},
54+
"scripts": {
55+
"cs-check": "php-cs-fixer fix --dry-run --diff",
56+
"cs-fix": "php-cs-fixer fix",
57+
"mutation-testing": "infection --threads=4",
58+
"pre-commit": [
59+
"@cs-check",
60+
"@static-analysis",
61+
"@tests"
62+
],
63+
"static-analysis": "phpstan analyse --level 5 src",
64+
"tests": "phpunit --testdox"
65+
}
66+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* This file is part of php-fast-forward/iterators.
7+
*
8+
* This source file is subject to the license that is bundled
9+
* with this source code in the file LICENSE.
10+
*
11+
* @link https://github.com/php-fast-forward/iterators
12+
* @copyright Copyright (c) 2025 Felipe Sayão Lobato Abreu <[email protected]>
13+
* @license https://opensource.org/licenses/MIT MIT License
14+
*/
15+
16+
use FastForward\Iterator\ChunkedIteratorAggregate;
17+
18+
use function FastForward\Iterator\debugIterable;
19+
20+
require_once dirname(__DIR__) . '/vendor/autoload.php';
21+
22+
/**
23+
* Sample dataset to be chunked.
24+
*
25+
* @var array<int, int> $data
26+
*/
27+
$data = range(1, 10);
28+
29+
/**
30+
* Creates a ChunkedIteratorAggregate with a chunk size of 3.
31+
*
32+
* This splits the data into subarrays of at most 3 elements each.
33+
*
34+
* @var ChunkedIteratorAggregate<int> $chunkedIterator
35+
*/
36+
$chunkedIterator = new ChunkedIteratorAggregate($data, 3);
37+
38+
/**
39+
* Creates a ChunkedIteratorAggregate with a chunk size of 4.
40+
*
41+
* This demonstrates how different chunk sizes affect iteration.
42+
*
43+
* @var ChunkedIteratorAggregate<int> $chunkedIteratorFour
44+
*/
45+
$chunkedIteratorFour = new ChunkedIteratorAggregate(new ArrayIterator($data), 4);
46+
47+
// Debugging the ChunkedIteratorAggregate output.
48+
debugIterable($chunkedIterator, 'ChunkedIteratorAggregate :: Chunk size 3');
49+
debugIterable($chunkedIteratorFour, 'ChunkedIteratorAggregate :: Chunk size 4');
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* This file is part of php-fast-forward/iterators.
7+
*
8+
* This source file is subject to the license that is bundled
9+
* with this source code in the file LICENSE.
10+
*
11+
* @link https://github.com/php-fast-forward/iterators
12+
* @copyright Copyright (c) 2025 Felipe Sayão Lobato Abreu <[email protected]>
13+
* @license https://opensource.org/licenses/MIT MIT License
14+
*/
15+
16+
use FastForward\Iterator\ClosureFactoryIteratorAggregate;
17+
18+
use function FastForward\Iterator\debugIterable;
19+
20+
require_once dirname(__DIR__) . '/vendor/autoload.php';
21+
22+
$len = 5;
23+
24+
/**
25+
* Generator function to produce values dynamically.
26+
*
27+
* @param int $len the number of values to generate
28+
*
29+
* @return Generator<int, string> a generator yielding formatted strings
30+
*/
31+
$generatorFactory = static function (int $len = 10) {
32+
for ($i = 0; $i < $len; ++$i) {
33+
yield 'Value: ' . ($i + $len);
34+
}
35+
};
36+
37+
/**
38+
* Array-based factory to showcase alternative iteration strategy.
39+
*
40+
* @param int $len the number of values to include
41+
*
42+
* @return ArrayIterator<int, string> an ArrayIterator wrapping a static array
43+
*/
44+
$arrayFactory = static fn (int $len = 10) => new ArrayIterator(array_map(static fn ($i) => 'Value: ' . ($i + $len), range(0, $len - 1)));
45+
46+
// Using ClosureFactoryIteratorAggregate with a Generator function
47+
$generatorIterator = new ClosureFactoryIteratorAggregate(static fn () => $generatorFactory($len));
48+
// or
49+
// $generatorIterator = new ClosureFactoryIteratorAggregate($generatorFactory);
50+
51+
// Using ClosureFactoryIteratorAggregate with an ArrayIterator
52+
$arrayIterator = new ClosureFactoryIteratorAggregate(static fn () => $arrayFactory($len));
53+
54+
debugIterable(
55+
$generatorIterator,
56+
'ClosureFactoryIteratorAggregate :: Generator Strategy :: First Iteration',
57+
);
58+
debugIterable(
59+
$generatorIterator,
60+
'ClosureFactoryIteratorAggregate :: Generator Strategy :: Second Iteration',
61+
);
62+
63+
debugIterable(
64+
$arrayIterator,
65+
'ClosureFactoryIteratorAggregate :: ArrayIterator Strategy :: First Iteration',
66+
);
67+
debugIterable(
68+
$arrayIterator,
69+
'ClosureFactoryIteratorAggregate :: ArrayIterator Strategy :: Second Iteration',
70+
);
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* This file is part of php-fast-forward/iterators.
7+
*
8+
* This source file is subject to the license that is bundled
9+
* with this source code in the file LICENSE.
10+
*
11+
* @link https://github.com/php-fast-forward/iterators
12+
* @copyright Copyright (c) 2025 Felipe Sayão Lobato Abreu <[email protected]>
13+
* @license https://opensource.org/licenses/MIT MIT License
14+
*/
15+
16+
use FastForward\Iterator\ClosureIteratorIterator;
17+
18+
use function FastForward\Iterator\debugIterable;
19+
20+
require_once dirname(__DIR__) . '/vendor/autoload.php';
21+
22+
$data = [1, 2, 3, 4, 5];
23+
24+
/**
25+
* Creates a ClosureIteratorIterator that doubles each value in an iterable.
26+
*
27+
* @param array<int, int> $data the array of integers to iterate over
28+
*
29+
* @return ClosureIteratorIterator<int, int> the transformed iterator
30+
*/
31+
$doubleIterator = new ClosureIteratorIterator(
32+
new ArrayIterator($data),
33+
static fn (int $value): int => $value * 2
34+
);
35+
36+
/**
37+
* Creates a ClosureIteratorIterator that transforms numbers into their string representations.
38+
*
39+
* @param array<int, int> $data the array of integers to iterate over
40+
*
41+
* @return ClosureIteratorIterator<int, string> the transformed iterator
42+
*/
43+
$stringIterator = new ClosureIteratorIterator(
44+
new ArrayIterator($data),
45+
static fn (int $value): string => "Number {$value}"
46+
);
47+
48+
// Running test iterations
49+
debugIterable($doubleIterator, 'ClosureIteratorIterator :: Doubling values');
50+
debugIterable($stringIterator, 'ClosureIteratorIterator :: Converting to strings');

0 commit comments

Comments
 (0)