Collections framework for PHP

Installs: 234

Dependents: 3

Stars: 35

Watchers: 7

Forks: 4

Open Issues: 17

Language: PHP

v1.0.0 2013-05-15 15:05 UTC

README

Goal

Convenient and safe way to work with collections.

Benefits

  • Rich maps (any type for keys).
  • Functional idioms:
    • immutable collections (safest and usable for most cases),
    • lazy operations — don't skimp on it.
  • Optional values (to solve NPE problem).

Installation

Colada currently may be installed as submodule for your Git project:

git submodule add git://github.com/alexeyshockov/colada.git vendor/colada

or throught Composer:

{
    "require": {
        "alexeyshockov/colada": "dev-master"
    }
}

Usage

Follow project's wiki for usage information and examples.

Detailed API documentation (for current stable release).

Playing with interactive shell

Colada includes small wrapper for standard PHP interactive shell, which adds some useful functions to it.

Lets play with it!

$ ./shell.sh
// Call use_colada() function to benefit from all shortcuts ;)
Interactive shell

php > use_colada();
php > d(collection(-2, -1, 0, 1, 2));
$var0 = array(0 => -2, 1 => -1, 2 => 0, 3 => 1, 4 => 2)
php > // Call above are identical to: $var0->mapBy(function($x) { return $x + 1; });
php > d($var0->mapBy(x()->increment()));
$var1 = array(0 => -1, 1 => 0, 2 => 1, 3 => 2, 4 => 3)
php > d($var0->acceptBy(x()->isPositive()));
$var2 = array(0 => 0, 1 => 1, 2 => 2)
php > d($var0->rejectBy(x()->isPositive()));
$var3 = array(0 => -2, 1 => -1)

php > d($var0->groupsBy(function($x) { return ($x >= 0 ? 'positive' : 'negative'); }));
$var4 = array(
  0 =>
  array(
    0 => 'negative',
    1 =>
    array(
      0 => -2,
      1 => -1,
    ),
  ),
  1 =>
  array(
    0 => 'positive',
    1 =>
    array(
      0 => 0,
      1 => 1,
      2 => 2,
    ),
  ),
)

Roadmap

Detailed roadmap can be found in appropriate page.