A list for a generic type of data.
- Class name: GenericList
- Namespace: PHPCollections\Collections
- This class extends: BaseCollection
- This class implements: ObjectCollectionInterface, IterableInterface, MergeableInterface,SortableInterface
private string $error
The error message to show when someone try to store a value of a different type than the specified in the type property.
- Visibility: private
private string $type
The type of data that will be stored.
- Visibility: private
void PHPCollections\Collections\GenericList::__construct(string $type, object ...$data)
Creates a new GenericList.
- Visibility: public
- $type string
- $data object ...
- \InvalidArgumentException
void PHPCollections\Collections\GenericList::add(mixed $value)
Adds a new object to the collection.
- Visibility: public
- $value mixed
- \InvalidArgumentException
GenericList PHPCollections\Collections\GenericList::diff(GenericList $newGenericList)
Gets the difference between two GenericList.
- Visibility: public
- $newGenericList \PHPCollections\Collections\GenericList
- \PHPCollections\Exceptions\InvalidOperationException
boolean PHPCollections\Collections\GenericList::equals(GenericList $collection)
Determines if two GenericList objects are equal.
- Visibility: public
- $collection \PHPCollections\Collections\GenericList
- \PHPCollections\Exceptions\InvalidOperationException
?GenericList PHPCollections\Collections\GenericList::filter(callable $callback)
Returns all the coincidences found for the given callback or null.
- Visibility: public
- $callback callable
void PHPCollections\Collections\GenericList::forEach(callable $callback)
Iterates over every element of the collection.
- Visibility: public
- $callback callable
?object PHPCollections\Collections\GenericList::get(int $offset)
Returns the object at the specified index or null if it's not defined.
- Visibility: public
- $offset int
- \OutOfRangeException
?GenericList PHPCollections\Collections\GenericList::map(callable $callback)
Updates elements in the collection by applying a given callback function.
- Visibility: public
- $callback callable
GenericList PHPCollections\Collections\GenericList::merge(GenericList $newGenericList)
Merges two GenericList into a new one.
- Visibility: public
- $data \PHPCollections\Collections\GenericList
- \InvalidArgumentException
mixed PHPCollections\Collections\GenericList::rand()
Returns a random element from the collection.
- Visibility: public
bool PHPCollections\Collections\GenericList::remove(int $offset)
Removes an item from the collection and repopulate the data container.
- Visibility: public
- $offset int
- \OutOfRangeException
void PHPCollections\Collections\GenericList::repopulate()
Repopulates the data container.
- Visibility: private
GenericList PHPCollections\Collections\GenericList::reverse()
Returns a new collection with the reversed values.
- Visibility: public
- \PHPCollections\Exceptions\InvalidOperationException
?GenericList PHPCollections\Collections\GenericList::slice(int $offset, ?int $length = null)
Returns a portion of the GenericList.
- Visibility: public
- $offset int
- $length int
?GenericList PHPCollections\Collections\GenericList::sort(callable $callback)
Returns a new GenericList with the values ordered by a given callback if couldn't sort returns null.
- Visibility: public
- $callback callable
bool PHPCollections\Collections\GenericList::update(integer $index, mixed $value)
Updates the value of the element at the given index.
- Visibility: public
- $index integer
- $value mixed
- \PHPCollections\Exceptions\InvalidOperationException
- \InvalidArgumentException