PHP Class Fusonic\Linq\Linq

Inheritance: implements IteratorAggregat\IteratorAggregate, implements Countabl\Countable
Show file Open project: fusonic/linq Class Usage Examples

Public Methods

Method 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

Method 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 method

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 method

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

all() public method

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

any() public method

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.
return 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 method

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.)
return double Average of items

chunk() public method

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

concat() public method

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

contains() public method

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

count() public method

Counts the elements of this Linq sequence.
public count ( ) : integer
return integer

distinct() public method

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

each() public method

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.
return void

elementAt() public method

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
return mixed Item at $index

elementAtOrNull() public method

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

except() public method

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

first() public method

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

firstOrNull() public method

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.
return mixed

from() public static method

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.
return Linq

getIterator() public method

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

groupBy() public method

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.
return Fusonic\Linq\GroupedLinq

intersect() public method

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

last() public method

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

lastOrNull() public method

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.
return mixed

max() public method

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.)
return double Maximum item value

min() public method

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.
return double Minimum item value

ofType() public method

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

orderBy() public method

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

orderByDescending() public method

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

range() public static method

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

select() public method

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.
return 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 method

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).
return 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 method

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

singleOrNull() public method

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.
return mixed

skip() public method

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

sum() public method

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.
return double The sum of all items.

take() public method

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

toArray() public method

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.
return array An array with all values.

where() public method

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