\YaLinqoEnumerablePagination

Trait of {@link Enumerable} containing pagination methods.

Summary

Methods
Properties
Constants
elementAt()
elementAtOrDefault()
first()
firstOrDefault()
firstOrFallback()
last()
lastOrDefault()
lastOrFallback()
single()
singleOrDefault()
singleOrFallback()
indexOf()
lastIndexOf()
findIndex()
findLastIndex()
skip()
skipWhile()
take()
takeWhile()
getIterator()
No public properties found
No constants found
No protected methods found
No protected properties found
N/A
No private methods found
No private properties found
N/A

Methods

elementAt()

elementAt(mixed  $key) : mixed

Returns the value at a specified key in a sequence.

Syntax: elementAt (key)

Returns the value at a specified key in a sequence.

If the type of source iterator implements \ArrayAccess, that implementation is used to obtain the value at the specified key. Otherwise, this method obtains the specified value.

This method throws an exception if key is not found. To instead return a default value when the specified key is not found, use the \elementAtOrDefault method.

Parameters

mixed $key

The key of the value to retrieve.

Throws

\UnexpectedValueException

If sequence does not contain value with specified key.

Returns

mixed —

The value at the key in the source sequence.

elementAtOrDefault()

elementAtOrDefault(mixed  $key, mixed  $default = null) : mixed

Returns the value at a specified key in a sequence or a default value if the key is not found.

Syntax: elementAtOrDefault (key [, default])

If the type of source iterator implements \ArrayAccess, that implementation is used to obtain the value at the specified key. Otherwise, this method obtains the specified value.

Parameters

mixed $key

The key of the value to retrieve.

mixed $default

Value to return if sequence does not contain value with specified key. Default: null.

Returns

mixed —

default value if the key is not found in the source sequence; otherwise, the value at the specified key in the source sequence.

first()

first(callable|null  $predicate = null) : mixed

Returns the first element of a sequence.

Syntax: first ()

Returns the first element of a sequence.

The first method throws an exception if source contains no elements. To instead return a default value when the source sequence is empty, use the \firstOrDefault method.

Syntax: first (predicate {(v, k) ==> result})

Returns the first element in a sequence that satisfies a specified condition.

The first method throws an exception if no matching element is found in source. To instead return a default value when no matching element is found, use the \firstOrDefault method.

Parameters

callable|null $predicate

{(v, k) ==> result} A function to test each element for a condition. Default: true.

Throws

\UnexpectedValueException

If source contains no matching elements.

Returns

mixed —

If predicate is null: the first element in the specified sequence. If predicate is not null: The first element in the sequence that passes the test in the specified predicate function.

firstOrDefault()

firstOrDefault(mixed  $default = null, callable|null  $predicate = null) : mixed

Returns the first element of a sequence, or a default value if the sequence contains no elements.

Syntax: firstOrDefault ([default])

Returns the first element of a sequence, or a default value if the sequence contains no elements.

Syntax: firstOrDefault ([default [, predicate {(v, k) ==> result}]])

Returns the first element of the sequence that satisfies a condition or a default value if no such element is found.

If obtaining the default value is a costly operation, use \firstOrFallback method to avoid overhead.

Parameters

mixed $default

A default value.

callable|null $predicate

{(v, k) ==> result} A function to test each element for a condition. Default: true.

Returns

mixed —

If predicate is null: default value if source is empty; otherwise, the first element in source. If predicate is not null: default value if source is empty or if no element passes the test specified by predicate; otherwise, the first element in source that passes the test specified by predicate.

firstOrFallback()

firstOrFallback(callable  $fallback, callable|null  $predicate = null) : mixed

Returns the first element of a sequence, or the result of calling a fallback function if the sequence contains no elements.

Syntax: firstOrFallback ([fallback {() ==> value}])

Returns the first element of a sequence, or the result of calling a fallback function if the sequence contains no elements.

Syntax: firstOrFallback ([fallback {() ==> value} [, predicate {(v, k) ==> result}]])

Returns the first element of the sequence that satisfies a condition or the result of calling a fallback function if no such element is found.

The fallback function is not executed if a matching element is found. Use the firstOrFallback method if obtaining the default value is a costly operation to avoid overhead. Otherwise, use \firstOrDefault.

Parameters

callable $fallback

{() ==> value} A fallback function to return the default element.

callable|null $predicate

{(v, k) ==> result} A function to test each element for a condition. Default: true.

Returns

mixed —

If predicate is null: the result of calling a fallback function if source is empty; otherwise, the first element in source. If predicate is not null: the result of calling a fallback function if source is empty or if no element passes the test specified by predicate; otherwise, the first element in source that passes the test specified by predicate.

last()

last(callable|null  $predicate = null) : mixed

Returns the last element of a sequence.

Syntax: last ()

Returns the last element of a sequence.

The last method throws an exception if source contains no elements. To instead return a default value when the source sequence is empty, use the \lastOrDefault method.

Syntax: last (predicate {(v, k) ==> result})

Returns the last element in a sequence that satisfies a specified condition.

The last method throws an exception if no matching element is found in source. To instead return a default value when no matching element is found, use the \lastOrDefault method.

Parameters

callable|null $predicate

{(v, k) ==> result} A function to test each element for a condition. Default: true.

Throws

\UnexpectedValueException

If source contains no matching elements.

Returns

mixed —

If predicate is null: the last element in the specified sequence. If predicate is not null: The last element in the sequence that passes the test in the specified predicate function.

lastOrDefault()

lastOrDefault(mixed  $default = null, callable|null  $predicate = null) : mixed

Returns the last element of a sequence, or a default value if the sequence contains no elements.

Syntax: lastOrDefault ([default])

Returns the last element of a sequence, or a default value if the sequence contains no elements.

Syntax: lastOrDefault ([default [, predicate {(v, k) ==> result}]])

Returns the last element of the sequence that satisfies a condition or a default value if no such element is found.

If obtaining the default value is a costly operation, use \lastOrFallback method to avoid overhead.

Parameters

mixed $default

A default value.

callable|null $predicate

{(v, k) ==> result} A function to test each element for a condition. Default: true.

Returns

mixed —

If predicate is null: default value if source is empty; otherwise, the last element in source. If predicate is not null: default value if source is empty or if no element passes the test specified by predicate; otherwise, the last element in source that passes the test specified by predicate.

lastOrFallback()

lastOrFallback(callable  $fallback, callable|null  $predicate = null) : mixed

Returns the last element of a sequence, or the result of calling a fallback function if the sequence contains no elements.

Syntax: lastOrFallback ([fallback {() ==> value}])

Returns the last element of a sequence, or the result of calling a fallback function if the sequence contains no elements.

Syntax: lastOrFallback ([fallback {() ==> value} [, predicate {(v, k) ==> result}]])

Returns the last element of the sequence that satisfies a condition or the result of calling a fallback function if no such element is found.

The fallback function is not executed if a matching element is found. Use the lastOrFallback method if obtaining the default value is a costly operation to avoid overhead. Otherwise, use \lastOrDefault.

Parameters

callable $fallback

{() ==> value} A fallback function to return the default element.

callable|null $predicate

{(v, k) ==> result} A function to test each element for a condition. Default: true.

Returns

mixed —

If predicate is null: the result of calling a fallback function if source is empty; otherwise, the last element in source. If predicate is not null: the result of calling a fallback function if source is empty or if no element passes the test specified by predicate; otherwise, the last element in source that passes the test specified by predicate.

single()

single(callable|null  $predicate = null) : mixed

Returns the only element of a sequence, and throws an exception if there is not exactly one element in the sequence.

Syntax: single ()

Returns the only element of a sequence, and throws an exception if there is not exactly one element in the sequence.

The single method throws an exception if source contains no elements. To instead return a default value when the source sequence is empty, use the \singleOrDefault method.

Syntax: single (predicate {(v, k) ==> result})

Returns the only element of a sequence that satisfies a specified condition.

The single method throws an exception if no matching element is found in source. To instead return a default value when no matching element is found, use the \singleOrDefault method.

Parameters

callable|null $predicate

{(v, k) ==> result} A function to test each element for a condition. Default: true.

Throws

\UnexpectedValueException

If source contains no matching elements or more than one matching element.

Returns

mixed —

If predicate is null: the single element of the input sequence. If predicate is not null: The single element of the sequence that passes the test in the specified predicate function.

singleOrDefault()

singleOrDefault(mixed  $default = null, callable|null  $predicate = null) : mixed

Returns the only element of a sequence, or a default value if the sequence contains no elements.

Syntax: singleOrDefault ([default])

Returns the only element of a sequence, or a default value if the sequence contains no elements.

Syntax: singleOrDefault ([default [, predicate {(v, k) ==> result}]])

Returns the only element of the sequence that satisfies a condition or a default value if no such element is found.

If obtaining the default value is a costly operation, use \singleOrFallback method to avoid overhead.

Parameters

mixed $default

A default value.

callable|null $predicate

{(v, k) ==> result} A function to test each element for a condition. Default: true.

Throws

\UnexpectedValueException

If source contains more than one matching element.

Returns

mixed —

If predicate is null: default value if source is empty; otherwise, the single element of the source. If predicate is not null: default value if source is empty or if no element passes the test specified by predicate; otherwise, the single element of the source that passes the test specified by predicate.

singleOrFallback()

singleOrFallback(callable  $fallback, callable|null  $predicate = null) : mixed

Returns the only element of a sequence, or the result of calling a fallback function if the sequence contains no elements.

Syntax: singleOrFallback ([fallback {() ==> value}])

Returns the only element of a sequence, or the result of calling a fallback function if the sequence contains no elements.

Syntax: singleOrFallback ([fallback {() ==> value} [, predicate {(v, k) ==> result}]])

Returns the only element of the sequence that satisfies a condition or the result of calling a fallback function if no such element is found.

The fallback function is not executed if a matching element is found. Use the singleOrFallback method if obtaining the default value is a costly operation to avoid overhead. Otherwise, use \singleOrDefault.

Parameters

callable $fallback

{() ==> value} A fallback function to return the default element.

callable|null $predicate

{(v, k) ==> result} A function to test each element for a condition. Default: true.

Throws

\UnexpectedValueException

If source contains more than one matching element.

Returns

mixed —

If predicate is null: the result of calling a fallback function if source is empty; otherwise, the single element of the source. If predicate is not null: the result of calling a fallback function if source is empty or if no element passes the test specified by predicate; otherwise, the single element of the source that passes the test specified by predicate.

indexOf()

indexOf(mixed  $value) : mixed

Searches for the specified value and returns the key of the first occurrence.

Syntax: indexOf (value)

To search for the zero-based index of the first occurence, call \toValues method first.

Parameters

mixed $value

The value to locate in the sequence.

Returns

mixed —

The key of the first occurrence of value, if found; otherwise, null.

lastIndexOf()

lastIndexOf(mixed  $value) : mixed

Searches for the specified value and returns the key of the last occurrence.

Syntax: lastIndexOf (value)

To search for the zero-based index of the last occurence, call \toValues method first.

Parameters

mixed $value

The value to locate in the sequence.

Returns

mixed —

The key of the last occurrence of value, if found; otherwise, null.

findIndex()

findIndex(callable  $predicate) : mixed

Searches for an element that matches the conditions defined by the specified predicate, and returns the key of the first occurrence.

Syntax: findIndex (predicate {(v, k) ==> result})

To search for the zero-based index of the first occurence, call \toValues method first.

Parameters

callable $predicate

{(v, k) ==> result} A function that defines the conditions of the element to search for.

Returns

mixed —

The key of the first occurrence of an element that matches the conditions defined by predicate, if found; otherwise, null.

findLastIndex()

findLastIndex(callable  $predicate) : mixed

Searches for an element that matches the conditions defined by the specified predicate, and returns the key of the last occurrence.

Syntax: findLastIndex (predicate {(v, k) ==> result})

To search for the zero-based index of the last occurence, call \toValues method first.

Parameters

callable $predicate

{(v, k) ==> result} A function that defines the conditions of the element to search for.

Returns

mixed —

The key of the last occurrence of an element that matches the conditions defined by predicate, if found; otherwise, null.

skip()

skip(integer  $count) : \YaLinqo\Enumerable

Bypasses a specified number of elements in a sequence and then returns the remaining elements.

Syntax: skip (count)

If source contains fewer than count elements, an empty sequence is returned. If count is less than or equal to zero, all elements of source are yielded.

The \take and skip methods are functional complements. Given a sequence coll and an integer n, concatenating the results of coll->take(n) and coll->skip(n) yields the same sequence as coll.

Parameters

integer $count

The number of elements to skip before returning the remaining elements.

Returns

\YaLinqo\Enumerable

A sequence that contains the elements that occur after the specified index in the input sequence.

skipWhile()

skipWhile(callable  $predicate) : \YaLinqo\Enumerable

Bypasses elements in a sequence as long as a specified condition is true and then returns the remaining elements.

Syntax: skipWhile (predicate {(v, k) ==> result})

This method tests each element of source by using predicate and skips the element if the result is true. After the predicate function returns false for an element, that element and the remaining elements in source are yielded and there are no more invocations of predicate. If predicate returns true for all elements in the sequence, an empty sequence is returned.

The \takeWhile and skipWhile methods are functional complements. Given a sequence coll and a pure function p, concatenating the results of coll->takeWhile(p) and coll->skipWhile(p) yields the same sequence as coll.

Parameters

callable $predicate

{(v, k) ==> result} A function to test each element for a condition.

Returns

\YaLinqo\Enumerable

A sequence that contains the elements from the input sequence starting at the first element in the linear series that does not pass the test specified by predicate.

take()

take(integer  $count) : \YaLinqo\Enumerable

Returns a specified number of contiguous elements from the start of a sequence.

Syntax: take (count)

Take enumerates source and yields elements until count elements have been yielded or source contains no more elements. If count is less than or equal to zero, source is not enumerated and an empty sequence is returned.

The take and \skip methods are functional complements. Given a sequence coll and an integer n, concatenating the results of coll->take(n) and coll->skip(n) yields the same sequence as coll.

Parameters

integer $count

The number of elements to return.

Returns

\YaLinqo\Enumerable

A sequence that contains the specified number of elements from the start of the input sequence.

takeWhile()

takeWhile(callable  $predicate) : \YaLinqo\Enumerable

Returns elements from a sequence as long as a specified condition is true.

Syntax: takeWhile (predicate {(v, k) ==> result})

The takeWhile method tests each element of source by using predicate and yields the element if the result is true. Enumeration stops when the predicate function returns false for an element or when source contains no more elements.

The takeWhile and \skipWhile methods are functional complements. Given a sequence coll and a pure function p, concatenating the results of coll->takeWhile(p) and coll->skipWhile(p) yields the same sequence as coll.

Parameters

callable $predicate

{(v, k) ==> result} A function to test each element for a condition.

Returns

\YaLinqo\Enumerable

A sequence that contains the elements from the input sequence that occur before the element at which the test no longer passes.

getIterator()

getIterator() : \Iterator

Retrieve an external iterator.

Returns

\Iterator