Download the PHP package jojo1981/typed-collection without Composer
On this page you can find all versions of the php package jojo1981/typed-collection. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download jojo1981/typed-collection
More information about jojo1981/typed-collection
Files in jojo1981/typed-collection
Informations about the package typed-collection
A typed collection data structure
Author: Joost Nijhuis [[email protected]](mailto:[email protected])
The typed collection is an ordered mutable sequence.
It is a data structure which is in fact a wrapper around an indexed array.
When a new collection is created the type
for the collection MUST be given.
The collection is of a certain type
and will guarantee all elements in the collection are of the same type
.
The type can be a primitive type
or a class/interface type
set for the collection.
Available types are:
- int (alias integer),
- float (aliases real, double or number)
- string (alias text)
- array
- object
- callable (alias callback)
- iterable
- class (class or interface name)
The \Jojo1981\TypedCollection\Collection
class is countable and is traversable (iterable).
The collection has the following convenient instance methods:
- getType(): string
- isEqualType(Collection $otherCollection): bool
- isEmpty(): bool
- isNonEmpty(): bool
- unshiftElement($element): void
- pushElement($element): void
- shiftElement()
- popElement()
- hasElement($element): bool
- pushElements(array $elements): void
- unshiftElements(array $elements): void
- setElements(array $elements): void
- removeElement($element): void
- indexOfElement($element): ?int
- getElementByIndex(int $index)
- getFirstElement()
- getLastElement()
- getFirstElementAsCollection(): Collection
- toArray(): array
- sortBy(callable $comparator): Collection
- map(string $type, callable $mapper): Collection
- flatMap(string $type, callable $mapper): Collection
- merge(Collection $otherCollection, Collection ...$otherCollections): void
- all(callable $predicate): bool
- some(callable $predicate): bool
- none(callable $predicate): bool
- forEach(callable $callback): void
- foldLeft(callable $callback, $initial = null)
- foldRight(callable $callback, $initial = null)
- filter(callable $predicate): Collection
- find(callable $predicate)
- group(callable $predicate, callable ...$predicates): Collection
- partition(callable $predicate): Collection
- slice(int $offset, ?int $length = null): Collection
- clear(): void
- count(): int
- getIterator(): CollectionIterator
- isEqualCollection(Collection $otherCollection, ?callable $predicate = null, bool $strict = false): bool
The \Jojo1981\TypedCollection\Collection
has a static method createFromCollections
.
Multiple collection of the same type
can be merged together into one collection.