Download the PHP package jojo1981/typed-set without Composer
On this page you can find all versions of the php package jojo1981/typed-set. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package typed-set
A typed set data structure
Author: Joost Nijhuis [[email protected]](mailto:[email protected])
The typed set is an unordered mutable set.
When a new set is created the type
for the set MUST be given.
Also a set can be created based on elements by using: \Jojo1981\TypedSet\Set::createFromElements
.
The set is of a certain type
and will guarantee all elements in the set are of the same type
.
The type can be a primitive type
or a class/interface type
set for the collection.
Elements are considered as equal when the hash is the same.
The hash can be retrieved when the element is an instance of: \Jojo1981\TypedSet\HashableInterface
or
when there is a handler which support the type. Handlers are classes which are implementing
the interface: \Jojo1981\TypedSet\HandlerInterface
and are registered to the GlobalHandler
.
The HashableInterface
has a higher precedence than the handlers.
The GlobalHandler
is a singleton which can be configured during the bootstrap of your application.
Default handlers and custom handlers can be enabled.
When the element is an object which does not implement: HashableInterface
and no handler support the
element the fallback will be that a hash will be generated based on the object hash.
This Set will be a set which has unique object instances.
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\TypedSet\Set
class is countable and traversable (iterable).
The set has the following convenient instance methods:
- add($element): void
- addAll(array $elements = []): void
- contains($element): bool
- remove($element): void
- clear(): void
- isEmpty(): bool
- isNonEmpty(): bool
- toArray(): array
- getType(): string
- isEqualType(TypeInterface $type): bool
- isEqual(Set $other): bool
- compare(Set $other): DifferenceResult
- map(callable $mapper, ?string $type = null): Set
- filter(callable $predicate): Set
- find(callable $predicate): mixed
- all(callable $predicate): bool
- some(callable $predicate): bool
- none(callable $predicate): bool
- count(): int
The \Jojo1981\TypedSet\Set
has a static method createFromElements
.
Installation
Library
Composer
Basic usage
Configuring the GlobalHandler
All versions of typed-set with dependencies
ext-json Version *
jojo1981/contracts Version ^1.0
jojo1981/php-types Version ^4.0