Skip to content

Commit e36a72e

Browse files
committed
transformation for small collection added
1 parent 2534de0 commit e36a72e

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace SimpleAsFuck\ApiToolkit\Service\Transformation;
6+
7+
final class Collection
8+
{
9+
/**
10+
* @template TValue
11+
* @param iterable<TValue> $transformed
12+
* @param Transformer<TValue> $transformer
13+
* @return array<int, \stdClass|\JsonSerializable>
14+
*/
15+
public static function toApi(iterable $transformed, Transformer $transformer): array
16+
{
17+
$apiArray = [];
18+
foreach ($transformed as $value) {
19+
$apiArray[] = $transformer->toApi($value);
20+
}
21+
return $apiArray;
22+
}
23+
}

0 commit comments

Comments
 (0)