bcen / yauc
This package is abandoned and no longer maintained.
No replacement package was suggested.
Yet Another Underscore Clone
0.0.8
2013-02-10 02:27 UTC
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();