dev-master
9999999-devKind of like LoDash but in PHP and lighter
MIT
The Requires
- php >=7.1
The Development Requires
by Hermanto Lim
Wallogit.com
2017 © Pedro Peláez
Kind of like LoDash but in PHP and lighter
Kind of Like LoDash but smaller, (*1)
NOTE: Require at least PHP VERSION 7.1, (*2)
composer require nonsensecreativity\dash, (*3)
Import and call the lib static method, (*4)
use function NSC\Dash\Iterables;
/**
* All iterable hook always provide
* - The current value
* - The current key
* - The iterable set
*
* @param int $v
* @param int $k
* @param iterable $itr
* @return iterable
*/
$flatMap = Iterables::flatMap([1, 2, 3, 4], function(int $v, int $k, iterable $itr) {
return [$v + 1, $v];
});
or use via dash static method which will automatically redirecting the called method to proper class, (*5)
use NSC\Dash\Dash;
Dash::flatMapDeep(
['a', [ 'b', [ 'c', [ 'd' ] ] ] ],
function(string $v, int $k, iterable $itr) {
return [ $v, $v . ' FLATMAPDEEP' ];
}
);
or use sequence, (*6)
$seq = Sequence::from([1, [2, [3, [4, 5]]]]);
$seq->flatten()
->reverse()
->flatMap(function($v, $k, $iterable) {
return [$v, $v];
})
->result();
TODO, (*7)
Kind of like LoDash but in PHP and lighter
MIT