2017 © Pedro Peláez
 

library collection

image

rubicon/collection

  • Saturday, August 8, 2015
  • by ronan-gloo
  • Repository
  • 1 Watchers
  • 0 Stars
  • 3,998 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 11 Versions
  • 7 % Grown

The README.md

Collection Library

Searching

$collection = new Collection(['one', 'two']);

// search by element: true
$collection->contains('one');

// search by key: true
$collection->has(1);

// find the first index of the given element.
$collection->indexOf('one');

// get a Collection instance for all indexes of the given element
$collection->indexesOf('one');

Map | Reduce

The method reduce() can return any kind of value., (*1)

$collection = new Collection([1, 2, 3]);
$result = $collection
    ->map(function($item) {
        return $item * 2;
    })
    ->reduce(function($carry, $item) {
        return $item + $carry;
    });

echo $result; // 12

Filter / Reject

Filter accepts any valid callback, (*2)

// creates new collection with only string elements found in $collection
$filtered = $collection->filter('is_string');

// creates new collection with only string keys found in $collection
$filtered = $collection->filter('is_string', Collection::FILTER_KEY);

// Same as above, but reject all string keys
$filtered = $collection->reject('is_string', Collection::FILTER_KEY);

Mutable Interface

Various operations that change the collection state, (*3)

$collection = new MutableCollection;, (*4)

// set / unset key
$collection->set('key', 'value');
$collection->delete('key');

// Push element
$collection->add('value');

// remove all elements 'value'
$collection->remove('value');

// replace every occurrences of the element by a new one
$collection->replace('element', 'new one');

// Clear all collection elements
$collection->clear();

The Versions

08/08 2015

dev-master

9999999-dev

  Sources   Download

The Requires

  • php >=5.5

 

The Development Requires

08/08 2015

1.3.5

1.3.5.0

  Sources   Download

The Requires

  • php >=5.5

 

The Development Requires

08/08 2015

1.3.4

1.3.4.0

  Sources   Download

The Requires

  • php >=5.5

 

The Development Requires

08/08 2015

1.3.3

1.3.3.0

  Sources   Download

The Requires

  • php >=5.5

 

The Development Requires

08/08 2015

1.3.2

1.3.2.0

  Sources   Download

The Requires

  • php >=5.5

 

The Development Requires

08/08 2015

1.3.1

1.3.1.0

  Sources   Download

The Requires

  • php >=5.5

 

The Development Requires

08/08 2015

1.3.0

1.3.0.0

  Sources   Download

The Requires

  • php >=5.5

 

The Development Requires

06/08 2015

1.2.1

1.2.1.0

  Sources   Download

The Requires

  • php >=5.5

 

The Development Requires

06/08 2015

1.2.0

1.2.0.0

  Sources   Download

The Requires

  • php >=5.5

 

The Development Requires

06/08 2015

1.1.0

1.1.0.0

  Sources   Download

The Requires

  • php >=5.5

 

The Development Requires

05/08 2015

1.0.0

1.0.0.0

  Sources   Download

The Requires

  • php >=5.5

 

The Development Requires