emonkak/underbar.php

该软件包已被废弃且不再维护。作者建议使用 emonkak/collection 软件包。

PHP 的集合处理库,类似于 Underscore.js

0.3.0 2013-10-09 01:55 UTC

This package is auto-updated.

Last update: 2022-02-01 12:23:55 UTC


README

Underbar.php 是一个 PHP 的集合处理库,类似于 underscore.js。

但并不追求与 underscore.js 完全兼容。

要求

许可证

MIT 许可证

开始使用

  1. 安装 Composer
  2. 创建 composer.json
  3. 执行 composer.phar install

composer.json

{
    "require": {
        "emonkak/underbar.php": "dev-master"
    }
}

示例

// There are also ArrayImpl and GeneratorImpl.
use Underbar\IteratorImpl as _;

// Take five elements from a infinite list of even numbers.
_::chain(0)
    ->iterate(function($n) { return $n + 1; })
    ->filter(function($n) { return $n % 2 === 0; })
    ->take(5)
    ->each(function($n) { echo $n, PHP_EOL; });
// => 0
//    2
//    4
//    6
//    8

// Get a first element.
echo _::first(array(100)), PHP_EOL;
// => 100

API 参考

http://emonkak.github.io/underbar.php/