PHP Trait YaLinqo\EnumerablePagination

显示文件 Open project: athari/yalinqo

Public Methods

Method Description
elementAt ( mixed $key ) : mixed Returns the value at a specified key in a sequence.
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.
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.
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.
first ( callable | null $predicate = null ) : mixed Returns the first element of a sequence.
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.
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.
getIterator ( ) : Iterator
indexOf ( mixed $value ) : mixed Searches for the specified value and returns the key of the first occurrence.
last ( callable | null $predicate = null ) : mixed Returns the last element of a sequence.
lastIndexOf ( mixed $value ) : mixed Searches for the specified value and returns the key of the last occurrence.
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.
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.
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.
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.
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.
skip ( integer $count ) : Enumerable Bypasses a specified number of elements in a sequence and then returns the remaining elements.
skipWhile ( callable $predicate ) : Enumerable Bypasses elements in a sequence as long as a specified condition is true and then returns the remaining elements.
take ( integer $count ) : Enumerable Returns a specified number of contiguous elements from the start of a sequence.
takeWhile ( callable $predicate ) : Enumerable Returns elements from a sequence as long as a specified condition is true.

Method Details

elementAt() public method

Syntax: elementAt (key)

Returns the value at a specified key in a sequence.

If the type of source iterator implements {@link 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 {@link elementAtOrDefault} method.

public elementAt ( mixed $key ) : mixed
$key mixed The key of the value to retrieve.
return mixed The value at the key in the source sequence.

elementAtOrDefault() public method

Syntax: elementAtOrDefault (key [, default])

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

public elementAtOrDefault ( mixed $key, mixed $default = null ) : mixed
$key mixed The key of the value to retrieve.
$default mixed Value to return if sequence does not contain value with specified key. Default: null.
return mixed default value if the key is not found in the source sequence; otherwise, the value at the specified key in the source sequence.

findIndex() public method

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

To search for the zero-based index of the first occurence, call {@link toValues} method first.

public findIndex ( callable $predicate ) : mixed
$predicate callable {(v, k) ==> result} A function that defines the conditions of the element to search for.
return mixed The key of the first occurrence of an element that matches the conditions defined by predicate, if found; otherwise, null.

findLastIndex() public method

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

To search for the zero-based index of the last occurence, call {@link toValues} method first.

public findLastIndex ( callable $predicate ) : mixed
$predicate callable {(v, k) ==> result} A function that defines the conditions of the element to search for.
return mixed The key of the last occurrence of an element that matches the conditions defined by predicate, if found; otherwise, null.

first() public method

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 {@link 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 {@link firstOrDefault} method.

public first ( callable | null $predicate = null ) : mixed
$predicate callable | null {(v, k) ==> result} A function to test each element for a condition. Default: true.
return 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() public method

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 {@link firstOrFallback} method to avoid overhead.

public firstOrDefault ( mixed $default = null, callable | null $predicate = null ) : mixed
$default mixed A default value.
$predicate callable | null {(v, k) ==> result} A function to test each element for a condition. Default: true.
return 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() public method

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 {@link firstOrDefault}.

public firstOrFallback ( callable $fallback, callable | null $predicate = null ) : mixed
$fallback callable {() ==> value} A fallback function to return the default element.
$predicate callable | null {(v, k) ==> result} A function to test each element for a condition. Default: true.
return 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.

getIterator() abstract public method

abstract public getIterator ( ) : Iterator
return Iterator

indexOf() public method

Syntax: indexOf (value)

To search for the zero-based index of the first occurence, call {@link toValues} method first.

public indexOf ( mixed $value ) : mixed
$value mixed The value to locate in the sequence.
return mixed The key of the first occurrence of value, if found; otherwise, null.

last() public method

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 {@link 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 {@link lastOrDefault} method.

public last ( callable | null $predicate = null ) : mixed
$predicate callable | null {(v, k) ==> result} A function to test each element for a condition. Default: true.
return 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.

lastIndexOf() public method

Syntax: lastIndexOf (value)

To search for the zero-based index of the last occurence, call {@link toValues} method first.

public lastIndexOf ( mixed $value ) : mixed
$value mixed The value to locate in the sequence.
return mixed The key of the last occurrence of value, if found; otherwise, null.

lastOrDefault() public method

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 {@link lastOrFallback} method to avoid overhead.

public lastOrDefault ( mixed $default = null, callable | null $predicate = null ) : mixed
$default mixed A default value.
$predicate callable | null {(v, k) ==> result} A function to test each element for a condition. Default: true.
return 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() public method

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 {@link lastOrDefault}.

public lastOrFallback ( callable $fallback, callable | null $predicate = null ) : mixed
$fallback callable {() ==> value} A fallback function to return the default element.
$predicate callable | null {(v, k) ==> result} A function to test each element for a condition. Default: true.
return 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() public method

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 {@link 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 {@link singleOrDefault} method.

public single ( callable | null $predicate = null ) : mixed
$predicate callable | null {(v, k) ==> result} A function to test each element for a condition. Default: true.
return 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() public method

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 {@link singleOrFallback} method to avoid overhead.

public singleOrDefault ( mixed $default = null, callable | null $predicate = null ) : mixed
$default mixed A default value.
$predicate callable | null {(v, k) ==> result} A function to test each element for a condition. Default: true.
return 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() public method

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 {@link singleOrDefault}.

public singleOrFallback ( callable $fallback, callable | null $predicate = null ) : mixed
$fallback callable {() ==> value} A fallback function to return the default element.
$predicate callable | null {(v, k) ==> result} A function to test each element for a condition. Default: true.
return 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.

skip() public method

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 {@link 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.

public skip ( integer $count ) : Enumerable
$count integer The number of elements to skip before returning the remaining elements.
return Enumerable A sequence that contains the elements that occur after the specified index in the input sequence.

skipWhile() public method

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 {@link 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.

public skipWhile ( callable $predicate ) : Enumerable
$predicate callable {(v, k) ==> result} A function to test each element for a condition.
return 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() public method

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 {@link 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.

public take ( integer $count ) : Enumerable
$count integer The number of elements to return.
return Enumerable A sequence that contains the specified number of elements from the start of the input sequence.

takeWhile() public method

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 {@link 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.

public takeWhile ( callable $predicate ) : Enumerable
$predicate callable {(v, k) ==> result} A function to test each element for a condition.
return Enumerable A sequence that contains the elements from the input sequence that occur before the element at which the test no longer passes.