Skip to content

Released: ArrayLookup 1.7.0

Compare
Choose a tag to compare
@samsonasik samsonasik released this 07 Sep 13:36
· 14 commits to main since this release
1.7.0
d3c90d4

1.7.0

ci build Code Coverage PHPStan

Add new Collector class, for collect filtered data, with new transformed each data found, for example, we have data:

$data = [
    ' a ',
    ' b ',
    ' c ',
    new \stdClass(),
];

we need to collect new data into new array with transformed no space in results.

Before

$newArray = [];

foreach ($data as $datum) {
    if (is_string($datum)) {
        $newArray[] = trim($datum);
    }
}

After, with Collector class

use ArrayLookup\Collector;


$when = fn (mixed $datum): bool => is_string($datum);
$limit = 2;
$transform = fn (string $datum): string => trim($datum);

$newArray = Collector::setUp($data)
       ->when($when)
       ->withLimit(2) // optional to only collect some data provided by limit config
       ->withTransform($transform)
       ->getResults(); // ['a', 'b', 'c']