Releases: samsonasik/ArrayLookup
Releases · samsonasik/ArrayLookup
Released: ArrayLookup 1.8.1
Released: ArrayLookup 1.8.0
1.8.0
Allow optional when on Collector
class, just transform, no filter.
$data = [
' a ',
' b ',
' c ',
];
transformed trim new data with:
use ArrayLookup\Collector;
$transform = fn (string $datum): string => trim($datum);
$newArray = Collector::setUp($data)
->withTransform($transform)
->getResults(); // ['a', 'b', 'c']
Released: ArrayLookup 1.7.0
1.7.0
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']
Released: ArrayLookup 1.6.0
1.6.0
This bring new ability to gather only limited found data on Finder::rows()
:
$data = [1, 2];
$filter = static fn($datum): bool => $datum >= 0;
$limit = 1;
var_dump(
Finder::rows($data, $filter, limit: $limit)
); // [1]
Released: ArrayLookup 1.5.0
Released ArrayLookup 1.4.0
1.4.0
Add new Finder::rows()
with the functionality is to get rows data filtered found:
use ArrayLookup\Finder;
$data = [6, 7, 8, 9];
var_dump(Finder::rows(
$data,
static fn($datum): bool => $datum > 6
)); // [7, 8, 9]
// WITH key array included, pass $key variable as 2nd arg on filter to be used in filter
var_dump(Finder::rows(
$data,
static fn($datum, $key): bool => $datum > 6 && $key > 1
)); // [8, 9]
// ... with PRESERVE original key
var_dump(Finder::rows(
$data,
static fn ($datum): bool => $datum > 6,
true
)); // [1 => 7, 2 => 8, 3 => 9]
1.3.0
1.3.0
Add $preserveKey flag ability to not preserve key on Finder::last()
$data = [6, 7, 8, 9];
$filter = static fn ($datum): bool => $datum > 5;
// RETURN the Array key, pass true to 3rd arg
// ... with PRESERVE original key
var_dump(\ArrayLookup\Finder::last($data, $filter, true)); // 3
// ... with RESORT key, first key is last record, pass false to 4th arg
var_dump(\ArrayLookup\Finder::last($data, $filter, true, false)); // 0
1.2.0
1.2.0
To allow search in both first
or last
to get the key instead of the row:
$data = [1, 2, 3];
$filter = static fn($datum): bool => $datum >= 1;
// RETURN the Array key, pass true to 3rd arg
var_dump(\ArrayLookup\Finder::first($data, $filter, true)) // 0
// RETURN the Array key, pass true to 3rd arg
var_dump(\ArrayLookup\Finder::last($data, $filter, true)) // 2
1.1.0
1.1.0
Added ability to filter by key as well in all AtLeast
, Only
, and Finder
:
$data = ['abc def', 'def ghi', 'ghi jkl'];
$filter = static fn(string $datum, int $key): bool => str_contains($datum, 'def') && $key >= 0;
Atleast::once($data, $filter); // true
$filter = static fn(string $datum, int $key): bool => str_contains($datum, 'not found datum') && $key >= 0;
Atleast::once($data, $filter); // false