Methods |
public
|
__construct<S>(Closure(S): Iterator<TKey, T> $callable, iterable<int, S> $parameter = [])
|
#
|
public
static
|
wrap<WrapKey, Wrap>(Closure|iterable $items): self<WrapKey, Wrap>
|
#
|
public
|
all(bool $preserveKeys = false): ($preserveKeys is false ? list<T> : array<array-key, T>)
Turns a collection into its array representation. Care should be taken when using this method when the collection has potential
duplicate keys. In case keys are preserved, the last of the duplicate keys
will be retained and the previous keys will be lost.
Turns a collection into its array representation. Care should be taken when using this method when the collection has potential
duplicate keys. In case keys are preserved, the last of the duplicate keys
will be retained and the previous keys will be lost.
Parameters
$preserveKeys |
Whether keys will be preserved during conversion.
Set this to false to prevent data loss when dealing
with duplicate keys.
|
Implements
|
#
|
public
|
any(Closure $predicate): bool
Returns true if any of the values in the collection
satisfies the $predicate . This method is short-circuiting, i.e., once the predicate
matches an item the remaining items will not be considered
anymore.
Returns true if any of the values in the collection
satisfies the $predicate . This method is short-circuiting, i.e., once the predicate
matches an item the remaining items will not be considered
anymore.
Implements
|
#
|
public
|
append<U>(U ...$items): self<int|TKey, T|U>
Appends one or more $items into the collection and returns
a new collection.
Appends one or more $items into the collection and returns
a new collection.
Implements
|
#
|
public
|
associate<U>(iterable $values): self<T, U>
Combines the collection to another iterable. The values of the collection will be the keys of the new collection
while the values of the other will be the values.
Combines the collection to another iterable. The values of the collection will be the keys of the new collection
while the values of the other will be the values.
Implements
|
#
|
public
|
chunk(int $size): self<int, non-empty-array<TKey, T>>
Returns a new collection containing the original items in the
collection split into chunks of given $size . This chunking operation preserves the keys. If the original
collection does not split evenly, the final chunk will be
smaller.
Returns a new collection containing the original items in the
collection split into chunks of given $size . This chunking operation preserves the keys. If the original
collection does not split evenly, the final chunk will be
smaller.
Implements
|
#
|
public
|
count(): int
|
#
|
public
|
cycle(): self<TKey, T>
Cycle indefinitely over a collection of items. NOTE: Be careful when using all() after calling cycle() as this
will exhaust all available memory trying to convert an infinite
collection. Make sure to call limit() after cycle() before
outputting the items.
Cycle indefinitely over a collection of items. NOTE: Be careful when using all() after calling cycle() as this
will exhaust all available memory trying to convert an infinite
collection. Make sure to call limit() after cycle() before
outputting the items.
Implements
|
#
|
public
|
diff(iterable ...$others): self<TKey, T>
Computes the difference of the collection against a series of other
iterables (i.e., collections, arrays, Traversable objects).
Computes the difference of the collection against a series of other
iterables (i.e., collections, arrays, Traversable objects).
Implements
|
#
|
public
|
diffKey(iterable ...$others): self<TKey, T>
Computes the difference of the collection against other iterables
using the keys for comparison.
Computes the difference of the collection against other iterables
using the keys for comparison.
Implements
|
#
|
public
|
drop(int $length): self<TKey, T>
Drops the first items with $length from the collection
and returns a new collection on the remaining items.
Drops the first items with $length from the collection
and returns a new collection on the remaining items.
Parameters
$length |
Number of items to drop from the start
|
Implements
|
#
|
public
|
every(Closure $predicate): bool
Returns true if all values in the collection satisfy the $predicate . This method is short-circuiting, i.e., if the predicate fails for the
first time, all remaining items will no longer be considered.
Returns true if all values in the collection satisfy the $predicate . This method is short-circuiting, i.e., if the predicate fails for the
first time, all remaining items will no longer be considered.
Implements
|
#
|
public
|
filter(?Closure $predicate = null): self<TKey, T>
Returns a new collection from items where $predicate returns true . If no $predicate is provided, this will just check for non-falsey values.
Returns a new collection from items where $predicate returns true . If no $predicate is provided, this will just check for non-falsey values.
Implements
|
#
|
public
|
filterKeys(?Closure $predicate = null): self<TKey, T>
Returns a new collection from keys where $predicate returns true . If $predicate is not provided, this will just check for non-falsey keys.
Returns a new collection from keys where $predicate returns true . If $predicate is not provided, this will just check for non-falsey keys.
Implements
|
#
|
public
|
filterWithKey(?Closure $predicate = null): self<TKey, T>
Returns a new collection from keys and values where $predicate returns true . If $predicate is not provided, this just checks for non-falsey keys and values.
Returns a new collection from keys and values where $predicate returns true . If $predicate is not provided, this just checks for non-falsey keys and values.
Implements
|
#
|
public
|
first(Closure $predicate, mixed $default = null): mixed
Gets the first item in the collection that passes the given $predicate . If none was found, this returns the $default value.
Gets the first item in the collection that passes the given $predicate . If none was found, this returns the $default value.
Implements
|
#
|
public
|
flip(): self<T, TKey>
Flips the keys and values and returns them as a new collection.
Flips the keys and values and returns them as a new collection.
Implements
|
#
|
public
|
forget(mixed ...$keys): self<TKey, T>
Removes items having the specified keys, then returns the remaining
items as a new collection.
Removes items having the specified keys, then returns the remaining
items as a new collection.
Implements
|
#
|
public
|
get(mixed $key, mixed $default = null): mixed
Gets the specific item from the collection having the specified key.
If none exists, returns the default value.
Gets the specific item from the collection having the specified key.
If none exists, returns the default value.
Implements
|
#
|
public
|
getIterator(): Generator<TKey, T, mixed, void>
|
#
|
public
|
has(mixed $key): bool
Checks if the collection has an item with the specified key.
Checks if the collection has an item with the specified key.
Implements
|
#
|
public
|
intersect(iterable ...$others): self<TKey, T>
Computes the intersection of the collection against other iterables.
Computes the intersection of the collection against other iterables.
Implements
|
#
|
public
|
intersectKey(iterable ...$others): self<TKey, T>
Computes the intersection of the collection against other iterables
using keys for comparison.
Computes the intersection of the collection against other iterables
using keys for comparison.
Implements
|
#
|
public
|
keys(): self<int, TKey>
Returns a new collection from keys of the original collection as
the new values.
Returns a new collection from keys of the original collection as
the new values.
Implements
|
#
|
public
|
limit(int $limit = -1, int $offset = 0): self<TKey, T>
Limit the number of values in the collection.
Limit the number of values in the collection.
Implements
|
#
|
public
|
map<U>(Closure $predicate): self<TKey, U>
Returns a new collection consisting of items transformed by applying
the mapping function $predicate . Only the values are passed to the closure. If you want to pass only
the keys, you need to use CollectionInterface::mapKeys() . If you
want both keys and values, you need CollectionInterface::mapWithKey() .
Returns a new collection consisting of items transformed by applying
the mapping function $predicate . Only the values are passed to the closure. If you want to pass only
the keys, you need to use CollectionInterface::mapKeys() . If you
want both keys and values, you need CollectionInterface::mapWithKey() .
Implements
|
#
|
public
|
mapKeys<UKey>(Closure $predicate): self<UKey, T>
Returns a new collection consisting of items transformed by the
mapping function $predicate that accepts the keys as inputs.
Returns a new collection consisting of items transformed by the
mapping function $predicate that accepts the keys as inputs.
Implements
|
#
|
public
|
mapWithKey<U>(Closure $predicate): self<TKey, U>
Returns a new collection consisting of items transformed by the
mapping function $predicate that accepts the keys and values
as inputs. The keys are left unchanged.
Returns a new collection consisting of items transformed by the
mapping function $predicate that accepts the keys and values
as inputs. The keys are left unchanged.
Implements
|
#
|
public
|
partition(Closure $predicate): self<int, CollectionInterface<TKey, T>>
Partition the collection into 2 tuples of collections. The first inner collection consists of items that have passed the $predicate .
The last inner collection consists of items that have failed the $predicate .
Partition the collection into 2 tuples of collections. The first inner collection consists of items that have passed the $predicate .
The last inner collection consists of items that have failed the $predicate .
Implements
|
#
|
public
|
reduce(Closure $predicate, mixed $initial = null): mixed
Reduce a collection using a $predicate . The reduction function is passed an accumulator value and the current
iterator value and returns a new accumulator. The accumulator is
initialised to $initial .
Reduce a collection using a $predicate . The reduction function is passed an accumulator value and the current
iterator value and returns a new accumulator. The accumulator is
initialised to $initial .
Implements
|
#
|
public
|
reductions<TAcc>(Closure $predicate, mixed $initial = null): self<int, TAcc>
Returns a new collection consisting of the intermediate values
of reducing the collection using a $predicate . The reduction $predicate is passed an $initial accumulator
and the current collection value and returns a new accumulator. Reductions returns a list of every accumulator along the way.
Returns a new collection consisting of the intermediate values
of reducing the collection using a $predicate . The reduction $predicate is passed an $initial accumulator
and the current collection value and returns a new accumulator. Reductions returns a list of every accumulator along the way.
Implements
|
#
|
public
|
reject(?Closure $predicate = null): self<TKey, T>
Returns a new collection from items where $predicate returns false.
Returns a new collection from items where $predicate returns false.
Implements
|
#
|
public
|
slice(int $start, ?int $length = null): self<TKey, T>
Takes a slice from a collection and returns it
as a new collection.
Takes a slice from a collection and returns it
as a new collection.
Parameters
$start |
Start offset
|
$length |
Length of collection (if not specified,
all remaining values from the collection
are used)
|
Implements
|
#
|
public
|
take(int $length): self<TKey, T>
Takes the first items with $length
and returns them as a new collection.
Takes the first items with $length
and returns them as a new collection.
Parameters
$length |
Number of items to take from the start
|
Implements
|
#
|
public
|
tap(Closure ...$callbacks): self<TKey, T>
Executes callbacks on each item of the collection. The passed callbacks are called with the value and key of
each item in the collection. The return value of the
callbacks are ignored.
Executes callbacks on each item of the collection. The passed callbacks are called with the value and key of
each item in the collection. The return value of the
callbacks are ignored.
Implements
|
#
|
public
|
values(): self<int, T>
Returns a new collection of values, ignoring the original keys.
Returns a new collection of values, ignoring the original keys.
Implements
|
#
|