mero / utils
This package is abandoned and no longer maintained.
No replacement package was suggested.
Library with features that increase productivity
0.1.0
2017-06-04 04:18 UTC
Requires
- php: >=5.4.9
Requires (Dev)
- phpunit/phpunit: ~4.4
- satooshi/php-coveralls: ~0.6.1
This package is auto-updated.
Last update: 2023-04-17 02:45:11 UTC
README
Library with features that increase productivity
Instalation with composer
- Open your project directory;
- Run
composer require mero/utils
to addMero Utils
in your project vendor.
Type classes
Collection
Object type extended array data type with additional methods.
count()
Counts all elements in the collection.
<?php use Mero\Utils\Collection; $var = new Collection(); $var[] = 'First element'; $var[] = 'Second element'; $var->count(); // Will return 2
find()
Finds the first value matching the closure condition.
<?php use Mero\Utils\Collection; $var = new Collection([ 'First element', 'Second element', 1, 4, 10, ]); $var->find(function($it) { return $it == 'Second element'; }); // Will return 'Second element'
findAll()
Finds all values matching the closure condition.
<?php use Mero\Utils\Collection; $var = new Collection([ 'First element', 'Second element', 1, 4, 10, 'Second element', 'Second element', ]); $var->findAll(function($it) { return $it == 'Second element'; }); // Will return ['Second element', 'Second element', 'Second element']
collect()
Iterates through this collection transforming each entry into a new value using the transform closure returning a list of transformed values.
<?php use Mero\Utils\Collection; $var = new Collection([1, 2, 3]); $var->collect(function($it) { return $it * 3; }); // Will return [3, 6, 9]
each()
Iterates through an Collection, passing each item to the given closure.
<?php use Mero\Utils\Collection; $var = new Collection([1, 2, 3]); $var->each(function($it) { echo $it."\n"; }); // Will return: // 1 // 2 // 3
eachWithIndex()
Iterates through an Collection, passing each item to the given closure.
<?php use Mero\Utils\Collection; $var = new Collection(['Element1', 'Element2', 'Element3']); $var->eachWithIndex(function($it, $index) { echo $index." - ".$it."\n"; }); // Will return: // 0 - Element1 // 1 - Element2 // 2 - Element3