final class Set implements Countable, IteratorAggregate, JsonSerializable, ArrayAccess (View source)

Constants

MIN_CAPACITY

Methods

__construct(iterable $values = [])

No description

void
add(TValue ...$values)

No description

void
allocate(int $capacity)

No description

int
capacity()

No description

void
clear()

No description

bool
contains(TValue ...$values)

No description

Set
copy()

No description

int
count()

Count elements of an object

Set
diff(Set $set)

No description

Set
filter(callable|null $callback = null)

No description

TValue
first()

No description

TValue
get(int $index)

No description

getIterator()

No description

Set
intersect(Set $set)

No description

bool
isEmpty()

No description

string
join(string $glue = '')

No description

mixed
jsonSerialize()

No description

TValue
last()

No description

Set
map(callable $callback)

No description

Set
merge(TValue> $values)

No description

TReturn|null
reduce(callable $callback, TInitial|null $initial = null)

No description

void
remove(TValue ...$values)

No description

void
reverse()

No description

Set
reversed()

No description

Set
slice(int $index, int|null $length = null)

No description

void
sort(callable|null $comparator = null)

No description

Set
sorted(callable|null $comparator = null)

No description

int|float
sum()

No description

array
toArray()

No description

Set
union(Set $set)

No description

Set
xor(Set $set)

No description

array
__serialize()

No description

void
__unserialize(array $data)

No description

bool
offsetExists(TKey $offset)

Whether a offset exists

mixed
offsetGet(TKey $offset)

Offset to retrieve

void
offsetSet(TKey $offset, TValue $value)

Offset to set

void
offsetUnset(TKey $offset)

Offset to unset

Details

__construct(iterable $values = [])

No description

Parameters

iterable $values

A traversable object or an array to use for the initial values.

void add(TValue ...$values)

No description

Parameters

TValue ...$values

Values to add to the set.

Return Value

void

void allocate(int $capacity)

No description

Parameters

int $capacity

Return Value

void

int capacity()

No description

Return Value

int

void clear()

No description

Return Value

void

bool contains(TValue ...$values)

No description

Parameters

TValue ...$values

Values to check.

Return Value

bool

Set copy()

No description

Return Value

Set

Returns a shallow copy of the set.

int count()

Count elements of an object

Return Value

int

The custom count as an integer.

The return value is cast to an integer.

Set diff(Set $set)

No description

Parameters

Set $set

Return Value

Set

A new set containing all values that were not in the other set.

Set filter(callable|null $callback = null)

No description

Parameters

callable|null $callback

callback ( mixed \$value ): bool
Optional callable which returns true if the value should be included, false otherwise. If a callback is not provided, only values which are true (see converting to boolean) will be included.

Return Value

Set

A new set containing all the values for which either the callback returned true, or all values that convert to true if a callback was not provided.

TValue first()

No description

Return Value

TValue

The first value in the set.

TValue get(int $index)

No description

Parameters

int $index

Return Value

TValue

The value at the requested index.

Traversable getIterator()

No description

Return Value

Traversable

An instance of an object implementing Iterator or Traversable

Set intersect(Set $set)

No description

Parameters

Set $set

Return Value

Set

The intersection of the current instance and another set.

bool isEmpty()

No description

Return Value

bool

string join(string $glue = '')

No description

Parameters

string $glue

Return Value

string

mixed jsonSerialize()

No description

Return Value

mixed

data which can be serialized by json_encode, which is a value of any type other than a resource.

TValue last()

No description

Return Value

TValue

The last value in the set.

Set map(callable $callback)

No description

Parameters

callable $callback

The callback to apply to each value in the set must have the following signature: callback ( mixed \$value ): mixed

Return Value

Set

Returns a new Ds\Set instance where each value is the result of applying the callback to each value of the set.

Set merge(TValue> $values)

No description

Parameters

TValue> $values

A traversable object or an array.

Return Value

Set

The result of adding all given values to the set, effectively the same as adding the values to a copy, then returning that copy. The current instance won't be affected.

TReturn|null reduce(callable $callback, TInitial|null $initial = null)

No description

Parameters

callable $callback

callback ( mixed \$carry , mixed \$value ): mixed
\$carry - The return value of the previous callback, or initial if it's the first iteration.
\$value - The value of the current iteration.

TInitial|null $initial

The initial value of the carry value. Can be null.

Return Value

TReturn|null

The return value of the final callback.

void remove(TValue ...$values)

No description

Parameters

TValue ...$values

The values to remove.

Return Value

void

void reverse()

No description

Return Value

void

Set reversed()

No description

Return Value

Set

A reversed copy of the set. The current instance is not affected.

Set slice(int $index, int|null $length = null)

No description

Parameters

int $index
int|null $length

Return Value

Set

A sub-set of the given range.

void sort(callable|null $comparator = null)

No description

Parameters

callable|null $comparator

The comparison function must return an integer less than, equal to, or greater than zero if the first argument is considered to be respectively less than, equal to, or greater than the second. Returning non-integer values from the comparison function, such as float, will result in an internal cast to int of the callback's return value. So values such as 0.99 and 0.1 will both be cast to an integer value of 0, which will compare such values as equal.

Return Value

void

Set sorted(callable|null $comparator = null)

No description

Parameters

callable|null $comparator

The comparison function must return an integer less than, equal to, or greater than zero if the first argument is considered to be respectively less than, equal to, or greater than the second. Returning non-integer values from the comparison function, such as float, will result in an internal cast to int of the callback's return value. So values such as 0.99 and 0.1 will both be cast to an integer value of 0, which will compare such values as equal.

Return Value

Set

Returns a sorted copy of the set.

int|float sum()

No description

Return Value

int|float

The sum of all the values in the set as either a float or int depending on the values in the set.

array toArray()

No description

Return Value

array

An array containing all the values in the same order as the set.

Set union(Set $set)

No description

Parameters

Set $set

Return Value

Set

A new set containing all the values of the current instance as well as another set.

Set xor(Set $set)

No description

Parameters

Set $set

Return Value

Set

A new set containing values in the current instance as well as another set, but not in both.

array __serialize()

No description

Return Value

array

void __unserialize(array $data)

No description

Parameters

array $data

Return Value

void

bool offsetExists(TKey $offset)

Whether a offset exists

Parameters

TKey $offset

An offset to check for.

Return Value

bool

true on success or false on failure.

The return value will be casted to boolean if non-boolean was returned.

mixed offsetGet(TKey $offset)

Offset to retrieve

Parameters

TKey $offset

The offset to retrieve.

Return Value

mixed

Can return all value types.

void offsetSet(TKey $offset, TValue $value)

Offset to set

Parameters

TKey $offset

The offset to assign the value to.

TValue $value

The value to set.

Return Value

void

No value is returned.

void offsetUnset(TKey $offset)

Offset to unset

Parameters

TKey $offset

The offset to unset.

Return Value

void

No value is returned.