ArrayLookup

🚀 A fast lookup library that help you verify and search array and Traversable data.

MIT License

Downloads
35.9K
Stars
17
Committers
1

Bot releases are hidden (Show)

ArrayLookup - Released: ArrayLookup 1.7.0 Latest Release

Published by samsonasik about 1 month ago

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']
ArrayLookup - Released: ArrayLookup 1.6.0

Published by samsonasik 7 months ago

1.6.0

ci build Code Coverage PHPStan

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]
ArrayLookup - Released: ArrayLookup 1.5.0

Published by samsonasik 8 months ago

1.5.0

ci build Code Coverage PHPStan

This bring some behaviour changes on Finder::rows() to keep string key when $preserveKey is disabled.

  • #14 [Finder] Fix string key on rows get when preserveKey disabled
  • #15 [Finder] Check numeric type as same with int on Finder::rows()
  • #16 [Finder] Don't increment new key when preserveKey
ArrayLookup - Released ArrayLookup 1.4.0

Published by samsonasik over 1 year ago

1.4.0

ci build Code Coverage PHPStan

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]
ArrayLookup - 1.3.0

Published by samsonasik almost 2 years ago

1.3.0

ci build Code Coverage PHPStan

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

ArrayLookup - 1.2.0

Published by samsonasik almost 2 years ago

1.2.0

ci build Code Coverage PHPStan

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
ArrayLookup - 1.1.0

Published by samsonasik almost 2 years ago

1.1.0

ci build Code Coverage PHPStan

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
ArrayLookup - 1.0.1

Published by samsonasik almost 2 years ago

ci build Code Coverage PHPStan

  • Add php 8.2 to CI build
  • Docblocks update.
ArrayLookup - 1.0.0

Published by samsonasik almost 2 years ago

Stable release 🎉 🎉 🎉

ci build Code Coverage PHPStan

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 :)

ArrayLookup - 0.9.0

Published by samsonasik almost 2 years ago

  • Fix memory leak on Finder::last()
ArrayLookup - 0.8.0

Published by samsonasik almost 2 years ago

ArrayLookup - 0.7.0

Published by samsonasik almost 2 years ago

ArrayLookup - 0.6.0

Published by samsonasik almost 2 years ago

ArrayLookup - 0.5.0

Published by samsonasik almost 2 years ago

ArrayLookup - 0.4.0

Published by samsonasik almost 2 years ago

ArrayLookup - 0.3.0

Published by samsonasik almost 2 years ago

ArrayLookup - 0.2.0

Published by samsonasik almost 2 years ago

ArrayLookup - 0.1.0

Published by samsonasik almost 2 years ago

ArrayLookup - 0.0.4

Published by samsonasik almost 2 years ago

ArrayLookup - 0.0.3

Published by samsonasik almost 2 years ago