Elgg
Version 6.1
|
A read-only interface to a (possibly mutable) group of items. More...
Public Member Functions | |
filter (callable $filter) | |
Returns a new collection only containing the elements which pass the filter. More... | |
contains ($item) | |
Returns true iff the item is in this collection at least once. More... | |
map (callable $mapper) | |
Take items of the collection and return a new collection with all the items having the $mapper applied to them. More... | |
A read-only interface to a (possibly mutable) group of items.
Read-only provides some nice guarantees that can be harnessed for things like caching, lazy evaluation, respecting HTTP semantics of GET/HEAD, etc.
We do not extend ArrayAccess, because:
Extensions may provide one or more of these features.
DO NOT EXTEND OR IMPLEMENT this interface outside of this package. Doing so would cause additions to the API to be breaking changes, which is not what we want. You have a couple of options for how to proceed:
Definition at line 28 of file Collection.php.
Elgg\Structs\Collection::contains | ( | $item | ) |
Returns true iff the item is in this collection at least once.
mixed | $item | The object or value to check for |
Implemented in Elgg\Structs\Collection\InMemory.
Elgg\Structs\Collection::filter | ( | callable | $filter | ) |
Returns a new collection only containing the elements which pass the filter.
callable | $filter | Receives an item. Return true to keep the item. |
Implemented in Elgg\Structs\Collection\InMemory.
Elgg\Structs\Collection::map | ( | callable | $mapper | ) |
Take items of the collection and return a new collection with all the items having the $mapper applied to them.
The callable is not guaranteed to execute immediately for each item.
callable | $mapper | Returns the mapped value |
Implemented in Elgg\Structs\Collection\InMemory.