PHP Class Fusonic\Linq\Linq

Inheritance: implements IteratorAggregat\IteratorAggregate, implements Countabl\Countable
Afficher le fichier Open project: fusonic/linq Class Usage Examples

Méthodes publiques

Méthode Description
__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.

Private Methods

Méthode Description
getFirst ( $func, $throw )
getLast ( $func, $throw )
getSelectIteratorOrInnerIterator ( $func )
getSingle ( $func, $throw )
getValueAt ( $index, $throwEx )
getWhereIteratorOrInnerIterator ( $func )
order ( $func, $direction = LinqHelper::LINQ_ORDER_ASC )

Method Details

__construct() public méthode

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() public méthode

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
Résultat mixed Returns the final result of $func.

all() public méthode

Determines whether all elements satisfy a condition.
public all ( callable $func ) : boolean
$func callable A function to test each element for a condition.
Résultat boolean True if every element passes the test in the specified func, or if the sequence is empty; otherwise, false.

any() public méthode

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.
Résultat 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() public méthode

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.)
Résultat double Average of items

chunk() public méthode

Splits the sequence in chunks according to $chunksize.
public chunk ( integer $chunksize ) : Linq
$chunksize integer Specifies how many elements are grouped together per chunk.
Résultat Linq

concat() public méthode

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.
Résultat Linq A new Linq object that contains the concatenated elements of the input sequence and the original Linq sequence.

contains() public méthode

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.
Résultat boolean True if $value is found within the sequence; otherwise false.

count() public méthode

Counts the elements of this Linq sequence.
public count ( ) : integer
Résultat integer

distinct() public méthode

Returns distinct item values of this
public distinct ( callable $func = null ) : Linq
$func callable
Résultat Linq Distinct item values of this

each() public méthode

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.
Résultat void

elementAt() public méthode

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
Résultat mixed Item at $index

elementAtOrNull() public méthode

Returns the element at a specified index or NULL if the index is out of range.
public elementAtOrNull ( $index ) : mixed
$index
Résultat mixed Item at $index

except() public méthode

Returns all elements except the ones of the given sequence.
public except ( array | Iterator $second ) : Linq
$second array | Iterator
Résultat Linq Returns all items of this not occuring in $second

first() public méthode

Returns the first element that satisfies a specified condition
public first ( callable $func = null ) : mixed
$func callable a func that returns boolean.
Résultat mixed

firstOrNull() public méthode

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.
Résultat mixed

from() public static méthode

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.
Résultat Linq

getIterator() public méthode

Retrieves the iterator of this Linq class.
public getIterator ( ) : Traversable
Résultat Traversable An instance of an object implementing Iterator or Traversable

groupBy() public méthode

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.
Résultat Fusonic\Linq\GroupedLinq

intersect() public méthode

Intersects the Linq sequence with second Iterable sequence.
public intersect ( $second ) : Linq
Résultat Linq intersected items

last() public méthode

Returns the last element that satisfies a specified condition.
public last ( callable $func = null ) : Object
$func callable a func that returns boolean.
Résultat Object Last item in this

lastOrNull() public méthode

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.
Résultat mixed

max() public méthode

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.)
Résultat double Maximum item value

min() public méthode

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.
Résultat double Minimum item value

ofType() public méthode

Filters the Linq object according to type.
public ofType ( string $type ) : Linq
$type string
Résultat Linq Filtered results according to $func

orderBy() public méthode

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.
Résultat Linq A new Linq instance whose elements are sorted ascending according to a key.

orderByDescending() public méthode

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.
Résultat Linq A new Linq instance whose elements are sorted descending according to a key.

range() public static méthode

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.
Résultat Linq An sequence that contains a range of sequential int numbers.

select() public méthode

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.
Résultat Linq A new Linq object whose elements are the result of invoking the transform function on each element of the original Linq object.

selectMany() public méthode

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).
Résultat 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() public méthode

Returns the only element that satisfies a specified condition.
public single ( callable $func = null ) : mixed
$func callable a func that returns boolean.
Résultat mixed

singleOrNull() public méthode

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.
Résultat mixed

skip() public méthode

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.
Résultat Linq A Linq object that contains the elements that occur after the specified index.

sum() public méthode

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.
Résultat double The sum of all items.

take() public méthode

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.
Résultat Linq A Linq object that contains the specified number of elements from the start.

toArray() public méthode

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.
Résultat array An array with all values.

where() public méthode

Filters the Linq object according to func return result.
public where ( callable $func ) : Linq
$func callable A func that returns boolean
Résultat Linq Filtered results according to $func