🚀 A fast lookup library that help you verify and search array and Traversable data.
MIT License
Bot releases are hidden (Show)
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']
Published by samsonasik 7 months ago
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]
Published by samsonasik 8 months ago
Published by samsonasik over 1 year ago
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]
Published by samsonasik almost 2 years ago
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
Published by samsonasik almost 2 years ago
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
Published by samsonasik almost 2 years ago
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
Published by samsonasik almost 2 years ago
Published by samsonasik almost 2 years ago
Stable release 🎉 🎉 🎉
A fast lookup library that help you verify and search array and Traversable data. It has the following features:
Features
✔️ Verify at least times: once()
, twice()
, times()
✔️ Verify exact times: once()
, twice()
, times()
✔️ Search data: first()
, last()
Read the README.md for the usage :)
Published by samsonasik almost 2 years ago
Finder::last()
Published by samsonasik almost 2 years ago
Published by samsonasik almost 2 years ago
Published by samsonasik almost 2 years ago
Published by samsonasik almost 2 years ago
Published by samsonasik almost 2 years ago
Published by samsonasik almost 2 years ago
Published by samsonasik almost 2 years ago
Published by samsonasik almost 2 years ago
Published by samsonasik almost 2 years ago
Published by samsonasik almost 2 years ago