bcen / yauc
此包已被 废弃 并不再维护。未建议替代包。
又一个 Underscore 克隆
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
用法
链式调用
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();
面向对象非链式模式
$mapped = _::init($stooges)->map(function($item) { return $item['name'] . ' is ' . $item['age'];}); $first = _::init($mapped)->first();
面向对象-静态调用
_::first(_::map($this->stooges, function($item) { return $item['name'] . ' is ' . $item['age']; }));
函数式
_first(_map($stooges, function($item) { return $item['name'] . ' is ' . $item['age']; }));
混合模式
_::init($stooges) ->makeChain() ->filter(...) ->map(...) ->pluck(...) ->disableChain() ->first()
方法委托
map 实现太慢?或者 pluck 没有正确提取?没问题!
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();