Skip to content

Repository files navigation

PHP Iterable

PHPUnitLatest Stable VersionLicensePHP Version

Handy utility methods that simplify iterable operations.

Requirements

  • Minimum version of PHP 8.2

Installation

composer require bonu/iterable

Usage

useBonu\Iterable\Iterables;
// ['FOO', 'BAR']
Iterables::map(
['foo', 'bar'],
staticfn (string$value): string => mb_strtoupper($value),
);
// ['FOO' => 'foo', 'BAR' => 'bar']
Iterables::mapWithKeys(
['foo', 'bar'],
staticfn (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);

License

This package is licensed under the MIT License.

About

Handy utility methods that simplify iterable operations.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages