PHP Класс Fusonic\Linq\Linq

Наследование: implements IteratorAggregat\IteratorAggregate, implements Countabl\Countable
Показать файл Открыть проект Примеры использования класса

Открытые методы

Метод Описание
__construct ( array | Iterator | IteratorAggregat\IteratorAggregate $dataSource ) Creates a new Linq object using the provided dataSource.
aggregate ( callable $func, mixed $seed = null ) : mixed Applies an accumulator function over a sequence.
all ( callable $func ) : boolean Determines whether all elements satisfy a condition.
any ( callable $func = null ) : boolean Determines whether any element exists or satisfies a condition by invoking $func.
average ( callable $func = null ) : double Computes the average of all numeric values. Uses $func to obtain the value on each element.
chunk ( integer $chunksize ) : Linq Splits the sequence in chunks according to $chunksize.
concat ( array | Iterator $second ) : Linq Concatenates this Linq object with the given sequence.
contains ( mixed $value ) : boolean Determines whether a sequence contains a specified element.
count ( ) : integer Counts the elements of this Linq sequence.
distinct ( callable $func = null ) : Linq Returns distinct item values of this
each ( callable $func ) : void Immediately performs the specified action on each element of the Linq sequence.
elementAt ( integer $index ) : mixed Returns the element at a specified index.
elementAtOrNull ( $index ) : mixed Returns the element at a specified index or NULL if the index is out of range.
except ( array | Iterator $second ) : Linq Returns all elements except the ones of the given sequence.
first ( callable $func = null ) : mixed Returns the first element that satisfies a specified condition
firstOrNull ( callable $func = null ) : mixed Returns the first element, or NULL if the sequence contains no elements.
from ( array | Iterator | IteratorAggregat\IteratorAggregate $dataSource ) : Linq Creates a new Linq object using the provided dataDataSource.
getIterator ( ) : Traversable Retrieves the iterator of this Linq class.
groupBy ( callable $keySelector ) : Fusonic\Linq\GroupedLinq Groups the object according to the $func generated key
intersect ( $second ) : Linq Intersects the Linq sequence with second Iterable sequence.
last ( callable $func = null ) : Object Returns the last element that satisfies a specified condition.
lastOrNull ( callable $func = null ) : mixed Returns the last element that satisfies a condition or NULL if no such element is found.
max ( callable $func = null ) : double Returns the maximum item value according to $func
min ( callable $func = null ) : double Gets the minimum item value of all items or by invoking a transform function on each item to get a numeric value.
ofType ( string $type ) : Linq Filters the Linq object according to type.
orderBy ( callable $func ) : Linq Sorts the elements in ascending order according to a key provided by $func.
orderByDescending ( callable $func ) : Linq Sorts the elements in descending order according to a key provided by $func.
range ( $start, $count ) : Linq Generates a sequence of integral numbers within a specified range.
select ( callable $func ) : Linq Projects each element into a new form by invoking the selector function.
selectMany ( callable $func ) : Linq Projects each element of a sequence to a new Linq and flattens the resulting sequences into one sequence.
single ( callable $func = null ) : mixed Returns the only element that satisfies a specified condition.
singleOrNull ( callable $func = null ) : mixed Returns the only element that satisfies a specified condition or NULL if no such element exists.
skip ( integer $count ) : Linq Bypasses a specified number of elements and then returns the remaining elements.
sum ( callable $func = null ) : double Gets the sum of all items or by invoking a transform function on each item to get a numeric value.
take ( integer $count ) : Linq Returns a specified number of contiguous elements from the start of a sequence
toArray ( callable $keySelector = null, callable $valueSelector = null ) : array Creates an Array from this Linq object with key/value selector(s).
where ( callable $func ) : Linq Filters the Linq object according to func return result.

Приватные методы

Метод Описание
getFirst ( $func, $throw )
getLast ( $func, $throw )
getSelectIteratorOrInnerIterator ( $func )
getSingle ( $func, $throw )
getValueAt ( $index, $throwEx )
getWhereIteratorOrInnerIterator ( $func )
order ( $func, $direction = LinqHelper::LINQ_ORDER_ASC )

Описание методов

__construct() публичный Метод

Creates a new Linq object using the provided dataSource.
public __construct ( array | Iterator | IteratorAggregat\IteratorAggregate $dataSource )
$dataSource array | Iterator | IteratorAggregat\IteratorAggregate A Traversable sequence as data source.

aggregate() публичный Метод

The aggregate method makes it simple to perform a calculation over a sequence of values. This method works by calling $func one time for each element. The first element of source is used as the initial aggregate value if $seed parameter is not specified. If $seed is specified, this value will be used as the first value.
public aggregate ( callable $func, mixed $seed = null ) : mixed
$func callable An accumulator function to be invoked on each element.
$seed mixed
Результат mixed Returns the final result of $func.

all() публичный Метод

Determines whether all elements satisfy a condition.
public all ( callable $func ) : boolean
$func callable A function to test each element for a condition.
Результат boolean True if every element passes the test in the specified func, or if the sequence is empty; otherwise, false.

any() публичный Метод

Determines whether any element exists or satisfies a condition by invoking $func.
public any ( callable $func = null ) : boolean
$func callable A function to test each element for a condition or NULL to determine if any element exists.
Результат boolean True if no $func given and the source sequence contains any elements or True if any elements passed the test in the specified func; otherwise, false.

average() публичный Метод

Computes the average of all numeric values. Uses $func to obtain the value on each element.
public average ( callable $func = null ) : double
$func callable A func that returns any numeric type (int, float etc.)
Результат double Average of items

chunk() публичный Метод

Splits the sequence in chunks according to $chunksize.
public chunk ( integer $chunksize ) : Linq
$chunksize integer Specifies how many elements are grouped together per chunk.
Результат Linq

concat() публичный Метод

Concatenates this Linq object with the given sequence.
public concat ( array | Iterator $second ) : Linq
$second array | Iterator A sequence which will be concatenated with this Linq object.
Результат Linq A new Linq object that contains the concatenated elements of the input sequence and the original Linq sequence.

contains() публичный Метод

This function will use php strict comparison (===). If you need custom comparison use the Linq::any($func) method.
public contains ( mixed $value ) : boolean
$value mixed The value to locate in the sequence.
Результат boolean True if $value is found within the sequence; otherwise false.

count() публичный Метод

Counts the elements of this Linq sequence.
public count ( ) : integer
Результат integer

distinct() публичный Метод

Returns distinct item values of this
public distinct ( callable $func = null ) : Linq
$func callable
Результат Linq Distinct item values of this

each() публичный Метод

Immediately performs the specified action on each element of the Linq sequence.
public each ( callable $func ) : void
$func callable A func that will be evaluated for each item in the linq sequence.
Результат void

elementAt() публичный Метод

This method throws an exception if index is out of range. To instead return NULL when the specified index is out of range, use the elementAtOrNull method.
public elementAt ( integer $index ) : mixed
$index integer
Результат mixed Item at $index

elementAtOrNull() публичный Метод

Returns the element at a specified index or NULL if the index is out of range.
public elementAtOrNull ( $index ) : mixed
$index
Результат mixed Item at $index

except() публичный Метод

Returns all elements except the ones of the given sequence.
public except ( array | Iterator $second ) : Linq
$second array | Iterator
Результат Linq Returns all items of this not occuring in $second

first() публичный Метод

Returns the first element that satisfies a specified condition
public first ( callable $func = null ) : mixed
$func callable a func that returns boolean.
Результат mixed

firstOrNull() публичный Метод

Returns the first element, or NULL if the sequence contains no elements.
public firstOrNull ( callable $func = null ) : mixed
$func callable a func that returns boolean.
Результат mixed

from() публичный статический Метод

This is the recommended way for getting a new Linq instance.
public static from ( array | Iterator | IteratorAggregat\IteratorAggregate $dataSource ) : Linq
$dataSource array | Iterator | IteratorAggregat\IteratorAggregate A Traversable sequence as data source.
Результат Linq

getIterator() публичный Метод

Retrieves the iterator of this Linq class.
public getIterator ( ) : Traversable
Результат Traversable An instance of an object implementing Iterator or Traversable

groupBy() публичный Метод

Groups the object according to the $func generated key
public groupBy ( callable $keySelector ) : Fusonic\Linq\GroupedLinq
$keySelector callable a func that returns an item as key, item can be any type.
Результат Fusonic\Linq\GroupedLinq

intersect() публичный Метод

Intersects the Linq sequence with second Iterable sequence.
public intersect ( $second ) : Linq
Результат Linq intersected items

last() публичный Метод

Returns the last element that satisfies a specified condition.
public last ( callable $func = null ) : Object
$func callable a func that returns boolean.
Результат Object Last item in this

lastOrNull() публичный Метод

Returns the last element that satisfies a condition or NULL if no such element is found.
public lastOrNull ( callable $func = null ) : mixed
$func callable a func that returns boolean.
Результат mixed

max() публичный Метод

Returns the maximum item value according to $func
public max ( callable $func = null ) : double
$func callable A func that returns any numeric type (int, float etc.)
Результат double Maximum item value

min() публичный Метод

Gets the minimum item value of all items or by invoking a transform function on each item to get a numeric value.
public min ( callable $func = null ) : double
$func callable A func that returns any numeric type (int, float etc.) from the given element, or NULL to use the element itself.
Результат double Minimum item value

ofType() публичный Метод

Filters the Linq object according to type.
public ofType ( string $type ) : Linq
$type string
Результат Linq Filtered results according to $func

orderBy() публичный Метод

Sorts the elements in ascending order according to a key provided by $func.
public orderBy ( callable $func ) : Linq
$func callable A function to extract a key from an element.
Результат Linq A new Linq instance whose elements are sorted ascending according to a key.

orderByDescending() публичный Метод

Sorts the elements in descending order according to a key provided by $func.
public orderByDescending ( callable $func ) : Linq
$func callable A function to extract a key from an element.
Результат Linq A new Linq instance whose elements are sorted descending according to a key.

range() публичный статический Метод

Generates a sequence of integral numbers within a specified range.
public static range ( $start, $count ) : Linq
$start The value of the first integer in the sequence.
$count The number of sequential integers to generate.
Результат Linq An sequence that contains a range of sequential int numbers.

select() публичный Метод

Projects each element into a new form by invoking the selector function.
public select ( callable $func ) : Linq
$func callable A transform function to apply to each element.
Результат Linq A new Linq object whose elements are the result of invoking the transform function on each element of the original Linq object.

selectMany() публичный Метод

Projects each element of a sequence to a new Linq and flattens the resulting sequences into one sequence.
public selectMany ( callable $func ) : Linq
$func callable A func that returns a sequence (array, Linq, Iterator).
Результат Linq A new Linq object whose elements are the result of invoking the one-to-many transform function on each element of the input sequence.

single() публичный Метод

Returns the only element that satisfies a specified condition.
public single ( callable $func = null ) : mixed
$func callable a func that returns boolean.
Результат mixed

singleOrNull() публичный Метод

Returns the only element that satisfies a specified condition or NULL if no such element exists.
public singleOrNull ( callable $func = null ) : mixed
$func callable a func that returns boolean.
Результат mixed

skip() публичный Метод

Bypasses a specified number of elements and then returns the remaining elements.
public skip ( integer $count ) : Linq
$count integer The number of elements to skip before returning the remaining elements.
Результат Linq A Linq object that contains the elements that occur after the specified index.

sum() публичный Метод

Gets the sum of all items or by invoking a transform function on each item to get a numeric value.
public sum ( callable $func = null ) : double
$func callable A func that returns any numeric type (int, float etc.) from the given element, or NULL to use the element itself.
Результат double The sum of all items.

take() публичный Метод

Returns a specified number of contiguous elements from the start of a sequence
public take ( integer $count ) : Linq
$count integer The number of elements to return.
Результат Linq A Linq object that contains the specified number of elements from the start.

toArray() публичный Метод

Creates an Array from this Linq object with key/value selector(s).
public toArray ( callable $keySelector = null, callable $valueSelector = null ) : array
$keySelector callable a func that returns the array-key for each element.
$valueSelector callable a func that returns the array-value for each element.
Результат array An array with all values.

where() публичный Метод

Filters the Linq object according to func return result.
public where ( callable $func ) : Linq
$func callable A func that returns boolean
Результат Linq Filtered results according to $func