bcen / yauc
Yet Another Underscore Clone
Installs: 133
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/bcen/yauc
Requires
- php: >=5.3.0
Requires (Dev)
- phpunit/phpunit: 3.7.*
This package is not auto-updated.
Last update: 2016-10-18 06:52:52 UTC
README
Usage
Chainable:
use Yauc\Underscore as _;
$stooges = array(
array(
'name' => 'curl',
'age' => 25
),
array(
'name' => 'moe',
'age' => 21
),
array(
'name' => 'larry',
'age' => 23
)
);
// 'curl is 25'
_::chain($stooges)
->map(function($item) { return $item['name'] . ' is ' . $item['age'];})
->first()
->value();
OOP non-chain mode:
$mapped = _::init($stooges)->map(function($item) { return $item['name'] . ' is ' . $item['age'];});
$first = _::init($mapped)->first();
OOP-static call:
_::first(_::map($this->stooges, function($item) {
return $item['name'] . ' is ' . $item['age'];
}));
Functional:
_first(_map($stooges, function($item) {
return $item['name'] . ' is ' . $item['age'];
}));
Hybrid:
_::init($stooges)
->makeChain()
->filter(...)
->map(...)
->pluck(...)
->disableChain()
->first()
Method Delegate
The implementation of map is too slow? or the pluck is not plucking? No problem!
class MyMethodDelegate extends \Yauc\Delegate\UnderscoreMethodDelegate
{
public static function map($item, $iterator)
{
// ...
}
}
_::setMethodDelegate('MyMethodDelegate');
_::chain($stooges)
->map(function($item) { return $item['name'] . ' is ' . $item['age'];})
->first()
->value();