Enumerable

The Enumerable trait will allow any object to work as a collection. The using class must implement the __each method, all other methods in this trait only depend on that method.

package

Default

Methods

Returns one element at a time from the enumerable. When implementing this method, you should only return values using the yield keyword. Do not use the return keyword to return values from this method!

__each() 
abstract

Returns true if all elements in the enumerable returns true from the callback.

all(callable $callback) : boolean

Otherwise returns false.

Arguments

$callback

callable

Response

boolean

Returns true if any elements in the enumerable returns true from the callback.

any(callable $callback) : boolean

Otherwise returns false.

Arguments

$callback

callable

Response

boolean

Returns the number of elements in the enumerable. If a callback is provided, only those alements that return true from the callback are counted.

count(callable $callback = null) : integer

Otherwise returns false.

Arguments

$callback

callable

Response

integer

Drops a number of elemens from the enumerable and returns the remaining elements as an EnumerableArray.

drop(integer $numElems) : \Lasso3000\Enumerable\EnumerableArray

Arguments

$numElems

integer

Response

\Lasso3000\Enumerable\EnumerableArray

Drops elements until the provided callback returns true. The remaining elements are returned as an EnumerableArray.

dropWhile(callable $callback) : \Lasso3000\Enumerable\EnumerableArray

Arguments

$callback

callable

Response

\Lasso3000\Enumerable\EnumerableArray

Applies a callback on each element in the enumerable without returning any value.

each(callable $callback) : null

Arguments

$callback

callable

Response

null

Returns the first element in the enumerable that returns true from the callback.

find(callable $callback, mixed $default = null) : mixed

If no matching element can be found, the provided default is returned instead.

Arguments

$callback

callable

$default

mixed

Response

mixed

Returns all elements in the enumerable that returns true from the callback.

findAll(callable $callback) : \Lasso3000\Enumerable\EnumerableArray

Arguments

$callback

callable

Response

\Lasso3000\Enumerable\EnumerableArray

Returns the index where $needle can be found. If $needle cannot be found, null is returned.

findIndex(mixed $needle) : integer|null

$needle can be either a callable or a value.

Arguments

$needle

mixed

Response

integer|null

Applies callback to all elements in the enumerable and returns an EnumerableArray with new result.

map(callable $callback) : \Lasso3000\Enumerable\EnumerableArray

Arguments

$callback

callable

Response

\Lasso3000\Enumerable\EnumerableArray

Returns true if the provided argument is a member of the enumerable.

member(mixed $needle) : boolean

Otherwise returns false.

Arguments

$needle

mixed

Response

boolean

Returns true if no element in the enumerable returns true from the callback.

none(callable $callback) : boolean

Arguments

$callback

callable

Response

boolean

Returns true if exactly one element in the enumerable returns true from the callback.

one(callable $callback) : boolean

Arguments

$callback

callable

Response

boolean

Returns an EnumerableArray with two elements, one EnumerableArray with all elements in the enumerable that returns true from the callback, and one EnumerableArray with all elements in the enumerable that returns false from the callback.

partition(callable $callback) : \Lasso3000\Enumerable\EnumerableArray

Arguments

$callback

callable

Response

\Lasso3000\Enumerable\EnumerableArray

Reduces an enumerable into a single value by applying a callback to each element.

reduce(callable $callback, mixed $initialValue = null) : \Lasso3000\Enumerable\EnumerableArray

Arguments

$callback

callable

$initialValue

mixed

Response

\Lasso3000\Enumerable\EnumerableArray

Returns an EnumerableArray containing all elements in the enumerable that returns false from the callback.

reject(callable $callback) : \Lasso3000\Enumerable\EnumerableArray

Arguments

$callback

callable

Response

\Lasso3000\Enumerable\EnumerableArray

Applies a callback on each element in the enumerable in reverse order without returning any value.

reverseEach(callable $callback) : null

Arguments

$callback

callable

Response

null

Sorts the elements in the enumerable by using a callback.

sort(callable $callback) : \Lasso3000\Enumerable\EnumerableArray

Arguments

$callback

callable

Response

\Lasso3000\Enumerable\EnumerableArray

Takes a number of elemens from the enumerable and returns them as an EnumerableArray.

take(integer $numElems) : \Lasso3000\Enumerable\EnumerableArray

Arguments

$numElems

integer

Response

\Lasso3000\Enumerable\EnumerableArray

Takes elements from the enumerable until the provided callback returns false.

takeWhile(callable $callback) : \Lasso3000\Enumerable\EnumerableArray

The result is returned as an EnumerableArray.

Arguments

$callback

callable

Response

\Lasso3000\Enumerable\EnumerableArray