Handy utility methods that simplify iterable operations.
- Minimum version of PHP 8.2
composer require bonu/iterableuse Bonu\Iterable\Iterables;
// ['FOO', 'BAR']
Iterables::map(
['foo', 'bar'],
static fn (string $value): string => mb_strtoupper($value),
);
// ['FOO' => 'foo', 'BAR' => 'bar']
Iterables::mapWithKeys(
['foo', 'bar'],
static fn (string $value): array => [
mb_strtoupper($value) => $value,
],
);
// 'foo'
Iterables::first(['foo', 'bar']);
// false
Iterables::isEmpty(['foo', 'bar']);
// true
Iterables::isNotEmpty(['foo', 'bar']);
// ['foo', 'bar']
Iterables::keys(['foo' => 'bar', 'bar' => 'baz']);
// [[1, 2], [3]]
Iterables::chunk([1, 2, 3], 2);This package is licensed under the MIT License.