Skip to content

Releases: samsonasik/ArrayLookup

Released: ArrayLookup 2.5.0

19 Feb 15:40
2.5.0
0d5dae8

Choose a tag to compare

ci build Code Coverage PHPStan

What's Changed

  • Add new All::match() and All::none() to verify all match or none with given filter by @samsonasik in #41

1. All::match()

It verify that all items match the filter and data is non-empty.

use ArrayLookup\All;

$data = [1, 2, 3];
$filter = static fn($datum): bool => $datum > 0;

var_dump(All::match($data, $filter)) // true

$data = [1, 0, 3];
$filter = static fn($datum): bool => $datum > 0;

var_dump(All::match($data, $filter)) // false

$data = [];
$filter = static fn($datum): bool => $datum !== null;

var_dump(All::match($data, $filter)) // false

// WITH key array included, pass $key variable as 2nd arg on  filter to be used in filter

$data = ['abc', 'def'];
$filter = static fn($datum, $key): bool => $datum !== '' && $key >= 0;

var_dump(All::match($data, $filter)) // true

2. All::none()

It verify that no items match the filter (empty data returns true).

use ArrayLookup\All;

$data = [1, 2, 3];
$filter = static fn($datum): bool => $datum === 4;

var_dump(All::none($data, $filter)) // true

$data = [1, 2, 3];
$filter = static fn($datum): bool => $datum === 2;

var_dump(All::none($data, $filter)) // false

$data = [];
$filter = static fn($datum): bool => $datum !== null;

var_dump(All::none($data, $filter)) // true

// WITH key array included, pass $key variable as 2nd arg on  filter to be used in filter

$data = ['abc', 'def'];
$filter = static fn($datum, $key): bool => $key === 0 && $datum === 'abc';

var_dump(All::none($data, $filter)) // false

Full Changelog: 2.4.2...2.5.0

Released: ArrayLookup 2.4.2

17 Feb 05:59
2.4.2
62e0b92

Choose a tag to compare

ci build Code Coverage PHPStan

What's Changed

  • Fix no space on min vs max on Interval::isExclusiveOf() by @samsonasik in #40

Full Changelog: 2.4.1...2.4.2

Released: ArrayLookup 2.4.1

15 Feb 15:25
2.4.1
b1c641c

Choose a tag to compare

ci build Code Coverage PHPStan

What's Changed

  • Fix limit to only allow positive value on validation on Finder::rows() by @samsonasik in #39

Full Changelog: 2.4.0...2.4.1

Released: ArrayLookup 2.4.0

12 Feb 00:40
2.4.0
83ad00b

Choose a tag to compare

ci build Code Coverage PHPStan

What's Changed

  • Add Interval feature to verify in interval range: isInclusiveOf() and isExclusiveOf() by @samsonasik in #38

We already have AtLeast and AtMost to verify the lower and upper bounds. Now it’s time for something in between, meet Interval!

1. Interval::isInclusiveOf()

It verify that data has filtered found items within min and max (inclusive).

use ArrayLookup\Interval;

$orders = [
    ['status' => 'paid'],
    ['status' => 'paid'],
    ['status' => 'pending'],
    ['status' => 'paid'],
];

$filter = static fn(array $order): bool => $order['status'] === 'paid';

// inclusive means min and max boundaries are allowed
var_dump(Interval::isInclusiveOf($orders, $filter, 3, 5)) // true
var_dump(Interval::isInclusiveOf($orders, $filter, 2, 5)) // true

2. Interval::isExclusiveOf()

It verify that data has filtered found items between min and max (exclusive).

use ArrayLookup\Interval;

$orders = [
    ['status' => 'paid'],
    ['status' => 'paid'],
    ['status' => 'pending'],
    ['status' => 'paid'],
];

$filter = static fn(array $order): bool => $order['status'] === 'paid';

// exclusive means strictly between min and max
var_dump(Interval::isExclusiveOf($orders, $filter, 3, 5)) // false
var_dump(Interval::isExclusiveOf($orders, $filter, 2, 5)) // true

Full Changelog: 2.3.1...2.4.0

Released: ArrayLookup 2.3.1

09 Feb 23:28
2.3.1
dd3f2b8

Choose a tag to compare

ci build Code Coverage PHPStan

What's Changed

Full Changelog: 2.3.0...2.3.1

Released: ArrayLookup 2.3.0

25 Jan 20:15
2.3.0
0726711

Choose a tag to compare

ci build Code Coverage PHPStan

What's Changed

  • Add AtMost, this is to verify "no more than" :)

1. AtMost::once()

It verify that data has filtered found item at most once.

use ArrayLookup\AtMost;

$data = [1, 2, 3];
$filter = static fn($datum): bool => $datum === 1;

var_dump(AtMost::once($data, $filter)) // true

$data = [1, "1", 3];
$filter = static fn($datum): bool => $datum == 1;

var_dump(AtMost::once($data, $filter)) // false

// WITH key array included, pass $key variable as 2nd arg on  filter to be used in filter

$data = ['abc', 'def', 'some test'];
$filter = static fn(string $datum, int $key): bool => $datum === 'def' && $key === 1;

var_dump(AtMost::once($data, $filter)) // true

$data = ['abc', 'def', 'some test'];
$filter = static fn(string $datum, int $key): bool => $key > 0;

var_dump(AtMost::once($data, $filter)) // false

2. AtMost::twice()

It verify that data has filtered found items at most twice.

use ArrayLookup\AtMost;

$data = [1, "1", 2];
$filter = static fn($datum): bool => $datum == 1;

var_dump(AtMost::twice($data, $filter)) // true

$data = [1, "1", 2, 1];
$filter = static fn($datum): bool => $datum == 1;

var_dump(AtMost::twice($data, $filter)) // false

3. AtMost::times()

It verify that data has filtered found items at most times passed in 3rd arg.

use ArrayLookup\AtMost;

$data = [false, null, 0];
$filter = static fn($datum): bool => ! $datum;
$times = 3;

var_dump(AtMost::times($data, $filter, $times)) // true

$data = [false, null, 0, 0];
$filter = static fn($datum): bool => ! $datum;
$times = 3;

var_dump(AtMost::times($data, $filter, $times)) // false

Full Changelog: 2.2.0...2.3.0

Released: ArrayLookup 2.2.0

11 Jan 15:22
2.2.0
4ce3b4d

Choose a tag to compare

ci build Code Coverage PHPStan Downloads

What's Changed

Full Changelog: 2.1.1...2.2.0

Released: ArrayLookup 2.1.1

16 Dec 08:12
2.1.1
1e0c0e4

Choose a tag to compare

What's Changed

  • Make faster search on Finder::last() on SplFixedArray data by @samsonasik in #34

Full Changelog: 2.1.0...2.1.1

Released: ArrayLookup 2.1.0

04 Dec 22:55
2.1.0
e61c61c

Choose a tag to compare

Feature

Add new Finder::partition() functionality:

It splits data into 2 arrays: matching and non-matching, instead of 2 loops to get match and non-match, it just use single iteration, and already get both matching and non-matching data.

The valid example for this:

<?php
// Import CSV data and separate valid/invalid rows in one pass
$csvRows = $csvParser->parse('users.csv');
[$validUsers, $invalidUsers] = Finder::partition(
    $csvRows,
    fn($row) => $validator->validate($row)->isValid()
);

// Bulk insert valid users
$userRepository->bulkInsert($validUsers);

// Generate error report for invalid rows
$reportGenerator->createErrorReport($invalidUsers);

Full Changelog: 2.0.3...2.1.0

Released: ArrayLookup 2.0.3

25 Jun 02:40
2.0.3
3b815db

Choose a tag to compare

[DX] Early check nullable any type on Filter