24    public function add($element)
 
   26        $this->elements[] = $element;
 
   31        return isset($this->elements[
$key]) ? $this->elements[
$key] : 
null;
 
   36        return new self(array_filter($this->elements, 
$f));
 
   39    public function set(
$key, $value)
 
   41        $this->elements[
$key] = $value;
 
   44    public function remove($element)
 
   46        $key = array_search($element, $this->elements);
 
   52        $removed = $this->elements[
$key];
 
   53        unset($this->elements[
$key]);
 
   60        if ($this->
count() !== 1) {
 
   62                __CLASS__ . 
'::' . __METHOD__ . 
' requires that the collection has exactly one element, ' 
   63                . 
'"%d" elements found',
 
   68        return reset($this->elements);
 
   73        return reset($this->elements);
 
   78        return end($this->elements);
 
   81    public function map(\Closure $function)
 
   83        return new self(array_map($function, $this->elements));
 
   88        return count($this->elements);
 
   93        return new \ArrayIterator($this->elements);
 
   98        return isset($this->elements[$offset]);
 
  103        return $this->elements[$offset];
 
  108        $this->elements[$offset] = $value;
 
  113        unset($this->elements[$offset]);
 
An exception for terminatinating execution or to throw for unit testing.
Simple Array implementation of Collection.
map(\Closure $function)
Applies the given function to each element in the collection and returns a new collection with the el...
first()
Return the first element from the collection.
add($element)
Add an element to the collection.
last()
Return the last element from the collection.
offsetSet($offset, $value)
__construct(array $elements=array())
getOnlyElement()
Shorthand for getting a single element that also must be the only element in the collection.