# \YaLinqoEnumerable

A sequence of values indexed by keys, the primary class of YaLinqo.

A sequence of values indexed by keys, which supports various operations: generation, projection, filtering, ordering, joining, grouping, aggregation etc.

To create a Enumerable, call \YaLinqo\Enumerable::from (aliased as a global function \YaLinqo\from) or any of the generation functions. To convert to array, call \YaLinqo\Enumerable::toArrayDeep or any of the conversion functions.

## Summary

Methods
Properties
Constants
cycle()
emptyEnum()
from()
generate()
toInfinity()
matches()
toNegativeInfinity()
returnEnum()
range()
rangeDown()
rangeTo()
repeat()
split()
elementAt()
elementAtOrDefault()
first()
firstOrDefault()
firstOrFallback()
last()
lastOrDefault()
lastOrFallback()
single()
singleOrDefault()
singleOrFallback()
indexOf()
lastIndexOf()
findIndex()
findLastIndex()
skip()
skipWhile()
take()
takeWhile()
getIterator()
cast()
ofType()
select()
selectMany()
where()
orderByDir()
orderBy()
orderByDescending()
groupJoin()
join()
groupBy()
aggregate()
aggregateOrDefault()
average()
count()
max()
maxBy()
min()
minBy()
sum()
all()
any()
append()
concat()
contains()
distinct()
except()
intersect()
prepend()
union()
toArray()
toArrayDeep()
toList()
toListDeep()
toDictionary()
toJSON()
toLookup()
toKeys()
toValues()
toObject()
toString()
call()
each()
write()
writeLine()
No public properties found
No constants found
tryGetArrayCopy()
toArrayDeepProc()
toListDeepProc()
No protected properties found
N/A
No private methods found
No private properties found
N/A

## Methods

### cycle()

#### Throws

\InvalidArgumentException

If source is not array or Traversible or Enumerable.

\UnexpectedValueException

If source contains no elements (checked during enumeration).

#### Returns

\YaLinqo\Enumerable

Endless list of items repeating the source sequence.

### emptyEnum()

emptyEnum() : \YaLinqo\Enumerable

Returns an empty sequence.

Syntax: emptyEnum ()

#### Returns

\YaLinqo\Enumerable

### from()

#### Throws

\InvalidArgumentException

If source is not array or Traversible or Enumerable.

#### Returns

\YaLinqo\Enumerable

### generate()

generate(callable  $funcValue, mixed$seedValue = null, callable|null  $funcKey = null, mixed$seedKey = null) : \YaLinqo\Enumerable

Generates a sequence by mimicking a for loop.

Syntax: generate (funcValue {(v, k) ==> value} [, seedValue [, funcKey {(v, k) ==> key} [, seedKey]]])

If seedValue is null, the first value will be the result of calling funcValue on seedValue and seedKey. The same applies for seedKey.

#### Parameters

 callable $funcValue {(v, k) ==> value} State update function to run on value after every iteration of the generator loop. Default: value. mixed$seedValue Initial state of the generator loop for values. Default: null. callable|null $funcKey {(v, k) ==> key} State update function to run on key after every iteration of the generator loop. Default: increment. mixed$seedKey Initial state of the generator loop ofr keys. Default: 0.

#### Returns

\YaLinqo\Enumerable

### toInfinity()

toInfinity(integer  $start, integer$step = 1) : \YaLinqo\Enumerable

Generates a sequence of integral numbers to infinity.

Syntax: toInfinity ([start [, step]])

#### Parameters

 integer $start The first integer in the sequence. Default: 0. integer$step The difference between adjacent integers. Default: 1.

#### Returns

\YaLinqo\Enumerable

### matches()

#### Returns

\YaLinqo\Enumerable

### toNegativeInfinity()

toNegativeInfinity(integer  $start, integer$step = 1) : \YaLinqo\Enumerable

Generates a sequence of integral numbers to negative infinity.

Syntax: toNegativeInfinity ([start [, step]])

#### Parameters

 integer $start The first integer in the sequence. Default: 0. integer$step The difference between adjacent integers. Default: 1.

#### Returns

\YaLinqo\Enumerable

### returnEnum()

#### Returns

\YaLinqo\Enumerable

Observable sequence containing the single specified element.

### range()

#### Returns

\YaLinqo\Enumerable

A sequence that contains a range of integral numbers.

### rangeDown()

#### Returns

\YaLinqo\Enumerable

A sequence that contains a range of integral numbers.

### rangeTo()

#### Throws

\InvalidArgumentException

If step is not a positive number.

#### Returns

\YaLinqo\Enumerable

A sequence that contains a range of integral numbers.

### repeat()

repeat(integer  $element, integer$count = null) : \YaLinqo\Enumerable

Generates an sequence that contains one repeated value.

Syntax: repeat (element)

Generates an endless sequence that contains one repeated value.

Syntax: repeat (element, count)

Generates a sequence of specified length that contains one repeated value.

Keys in the generated sequence are sequental: 0, 1, 2 etc.

#### Parameters

 integer $element The value to be repeated. integer$count The number of times to repeat the value in the generated sequence. Default: null.

#### Throws

\InvalidArgumentException

If count is less than 0.

#### Returns

\YaLinqo\Enumerable

A sequence that contains a repeated value.

### split()

#### Returns

\YaLinqo\Enumerable

### elementAt()

#### 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()

#### 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()

#### 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()

#### 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()

#### Returns

mixed —

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

### lastIndexOf()

#### Returns

mixed —

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

### findIndex()

#### Returns

mixed —

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

### findLastIndex()

#### Returns

mixed —

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

### skip()

#### Returns

\YaLinqo\Enumerable

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

### skipWhile()

#### 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()

#### Returns

\YaLinqo\Enumerable

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

### takeWhile()

#### 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.

{@inheritdoc}

\Iterator

### cast()

#### Returns

\YaLinqo\Enumerable

An sequence that contains each element of the source sequence cast to the specified type.

### ofType()

#### Returns

\YaLinqo\Enumerable

A sequence that contains elements from the input sequence of the specified type.

### select()

select(callable  $selectorValue, callable|null$selectorKey = null) : \YaLinqo\Enumerable

Projects each element of a sequence into a new form.

Syntax: select (selectorValue {(v, k) ==> result} [, selectorKey {(v, k) ==> result}])

This projection method requires the transform functions, selectorValue and selectorKey, to produce one key-value pair for each value in the source sequence. If selectorValue returns a value that is itself a collection, it is up to the consumer to traverse the subsequences manually. In such a situation, it might be better for your query to return a single coalesced sequence of values. To achieve this, use the \selectMany() method instead of select. Although selectMany works similarly to select, it differs in that the transform function returns a collection that is then expanded by selectMany before it is returned.

#### Parameters

 callable $selectorValue {(v, k) ==> value} A transform function to apply to each value. callable|null$selectorKey {(v, k) ==> key} A transform function to apply to each key. Default: key.

#### Returns

\YaLinqo\Enumerable

A sequence whose elements are the result of invoking the transform functions on each element of source.

### selectMany()

#### Returns

\YaLinqo\Enumerable

A sequence whose elements are the result of invoking the one-to-many transform function on each element of the input sequence.

### where()

#### Returns

\YaLinqo\Enumerable

A sequence that contains elements from the input sequence that satisfy the condition.

### orderByDir()

#### Returns

\YaLinqo\OrderedEnumerable

### orderBy()

orderBy(callable|null  $keySelector = null, callable|integer|null$comparer = null) : \YaLinqo\OrderedEnumerable

Sorts the elements of a sequence in ascending order according to a key.

Syntax: orderBy ([{(v, k) ==> key} [, {(a, b) ==> diff}]])

Three methods are defined to extend the type \OrderedEnumerable, which is the return type of this method. These three methods, namely \OrderedEnumerable::thenBy, \OrderedEnumerable::thenByDescending and \OrderedEnumerable::thenByDir, enable you to specify additional sort criteria to sort a sequence. These methods also return an OrderedEnumerable, which means any number of consecutive calls to thenBy, thenByDescending or thenByDir can be made.

Because OrderedEnumerable inherits from Enumerable, you can call \orderBy, \orderByDescending or \orderByDir on the results of a call to orderBy, orderByDescending, orderByDir, thenBy, thenByDescending or thenByDir. Doing this introduces a new primary ordering that ignores the previously established ordering.

This method performs an unstable sort; that is, if the keys of two elements are equal, the order of the elements is not preserved. In contrast, a stable sort preserves the order of elements that have the same key. Internally, \usort is used.

#### Parameters

 callable|null $keySelector {(v, k) ==> key} A function to extract a key from an element. Default: value. callable|integer|null$comparer {(a, b) ==> diff} Difference between a and b: <0 if a0 if a>b. Can also be a combination of SORT_ flags.

#### Returns

\YaLinqo\OrderedEnumerable

### orderByDescending()

orderByDescending(callable|null  $keySelector = null, callable|integer|null$comparer = null) : \YaLinqo\OrderedEnumerable

Sorts the elements of a sequence in descending order according to a key.

Syntax: orderByDescending ([{(v, k) ==> key} [, {(a, b) ==> diff}]])

Three methods are defined to extend the type \OrderedEnumerable, which is the return type of this method. These three methods, namely \OrderedEnumerable::thenBy, \OrderedEnumerable::thenByDescending and \OrderedEnumerable::thenByDir, enable you to specify additional sort criteria to sort a sequence. These methods also return an OrderedEnumerable, which means any number of consecutive calls to thenBy, thenByDescending or thenByDir can be made.

Because OrderedEnumerable inherits from Enumerable, you can call \orderBy, \orderByDescending or \orderByDir on the results of a call to orderBy, orderByDescending, orderByDir, thenBy, thenByDescending or thenByDir. Doing this introduces a new primary ordering that ignores the previously established ordering.

This method performs an unstable sort; that is, if the keys of two elements are equal, the order of the elements is not preserved. In contrast, a stable sort preserves the order of elements that have the same key. Internally, \usort is used.

#### Parameters

 callable|null $keySelector {(v, k) ==> key} A function to extract a key from an element. Default: value. callable|integer|null$comparer {(a, b) ==> diff} Difference between a and b: <0 if a0 if a>b. Can also be a combination of SORT_ flags.

#### Returns

\YaLinqo\OrderedEnumerable

### groupJoin()

#### Returns

\YaLinqo\Enumerable

A sequence that contains elements that are obtained by performing a grouped join on two sequences.

### join()

#### Returns

\YaLinqo\Enumerable

### groupBy()

groupBy(callable|null  $keySelector = null, callable|null$valueSelector = null, callable|null  $resultSelectorValue = null, callable|null$resultSelectorKey = null) : \YaLinqo\Enumerable

Groups the elements of a sequence by its keys or a specified key selector function.

Syntax: groupBy ()

Groups the elements of a sequence by its keys.

Syntax: groupBy (keySelector {(v, k) ==> key})

Groups the elements of a sequence according to a specified key selector function.

Syntax: groupBy (keySelector {(v, k) ==> key}, valueSelector {(v, k) ==> value})

Groups the elements of a sequence according to a specified key selector function and projects the elements for each group by using a specified function.

Syntax: groupBy (keySelector {(v, k) ==> key}, valueSelector {(v, k) ==> value}, resultSelectorValue {(e, k) ==> value} [, resultSelectorKey {(e, k) ==> key}])

Groups the elements of a sequence according to a specified key selector function and creates a result value from each group and its key.

For all overloads except the last: the groupBy method returns a sequence of sequences, one inner sequence for each distinct key that was encountered. The outer sequence is yielded in an order based on the order of the elements in source that produced the first key of each inner sequence. Elements in a inner sequence are yielded in the order they appear in source.

#### Parameters

 callable|null $keySelector {(v, k) ==> key} A function to extract the key for each element. Default: key. callable|null$valueSelector {(v, k) ==> value} A function to map each source element to a value in the inner sequence. callable|null $resultSelectorValue {(e, k) ==> value} A function to create a result value from each group. callable|null$resultSelectorKey {(e, k) ==> key} A function to create a result key from each group.

#### Returns

\YaLinqo\Enumerable

A sequence of sequences indexed by a key.

### aggregate()

aggregate(callable  $func, mixed$seed = null) : mixed

Applies an accumulator function over a sequence. If seed is not null, its value is used as the initial accumulator value.

Syntax: aggregate (func {(a, v, k) ==> accum} [, seed])

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 in source. Each time func is called, aggregate passes both the element from the sequence and an aggregated value (as the first argument to func). If seed is null, the first element of source is used as the initial aggregate value. The result of func replaces the previous aggregated value. Aggregate returns the final result of func.

To simplify common aggregation operations, the standard query operators also include a general purpose count method, \count, and four numeric aggregation methods, namely \min, \max, \sum, and \average.

#### Parameters

 callable $func {(a, v, k) ==> accum} An accumulator function to be invoked on each element. mixed$seed If seed is not null, the first element is used as seed. Default: null.

#### Throws

\UnexpectedValueException

If seed is null and sequence contains no elements.

#### Returns

mixed —

The final accumulator value.

### aggregateOrDefault()

#### Returns

mixed —

The final accumulator value, or default if sequence is empty.

### average()

#### Throws

\UnexpectedValueException

If sequence contains no elements.

#### Returns

\YaLinqo\number —

The average of the sequence of values.

### count()

#### Returns

integer —

The number of elements in the input sequence.

### max()

#### Throws

\UnexpectedValueException

If sequence contains no elements.

#### Returns

\YaLinqo\number —

The maximum value in the sequence.

### maxBy()

maxBy(callable  $comparer, callable|null$selector = null) : \YaLinqo\number

Returns the maximum value in a sequence of values, using specified comparer.

Syntax: maxBy (comparer {(a, b) ==> diff})

Returns the maximum value in a sequence of values, using specified comparer.

Syntax: maxBy (comparer {(a, b) ==> diff}, selector {(v, k) ==> value})

Invokes a transform function on each element of a sequence and returns the maximum value, using specified comparer.

#### Parameters

 callable $comparer {(a, b) ==> diff} Difference between a and b: <0 if a0 if a>b callable|null$selector {(v, k) ==> value} A transform function to apply to each element. Default: value.

#### Throws

\UnexpectedValueException

If sequence contains no elements.

#### Returns

\YaLinqo\number —

The maximum value in the sequence.

### min()

#### Throws

\UnexpectedValueException

If sequence contains no elements.

#### Returns

\YaLinqo\number —

The minimum value in the sequence.

### minBy()

minBy(callable  $comparer, callable|null$selector = null) : \YaLinqo\number

Returns the minimum value in a sequence of values, using specified comparer.

Syntax: minBy (comparer {(a, b) ==> diff})

Returns the minimum value in a sequence of values, using specified comparer.

Syntax: minBy (comparer {(a, b) ==> diff}, selector {(v, k) ==> value})

Invokes a transform function on each element of a sequence and returns the minimum value, using specified comparer.

#### Parameters

 callable $comparer {(a, b) ==> diff} Difference between a and b: <0 if a0 if a>b callable|null$selector {(v, k) ==> value} A transform function to apply to each element. Default: value.

#### Throws

\UnexpectedValueException

If sequence contains no elements.

#### Returns

\YaLinqo\number —

The minimum value in the sequence.

### sum()

#### Returns

\YaLinqo\number —

The sum of the values in the sequence.

### all()

#### Returns

boolean —

true if every element of the source sequence passes the test in the specified predicate, or if the sequence is empty; otherwise, false.

### any()

#### Returns

boolean —

If predicate is null: true if the source sequence contains any elements; otherwise, false. If predicate is not null: true if any elements in the source sequence pass the test in the specified predicate; otherwise, false.

### append()

append(mixed  $value, mixed$key = null) : \YaLinqo\Enumerable

Appends a value to the end of the sequence.

Syntax: append (other, value)

Appends a value to the end of the sequence with null key.

Syntax: append (other, value, key)

Appends a value to the end of the sequence with the specified key.

#### Parameters

 mixed $value The value to append. mixed$key The key of the value to append.

#### Returns

\YaLinqo\Enumerable

A new sequence that ends with the value.

### concat()

#### Returns

\YaLinqo\Enumerable

A sequence that contains the concatenated elements of the two input sequences.

### contains()

#### Returns

boolean —

true if the source sequence contains an element that has the specified value; otherwise, false.

### distinct()

#### Returns

\YaLinqo\Enumerable

A sequence that contains distinct elements of the input sequence.

### except()

except(array|\Iterator|\IteratorAggregate|\YaLinqo\Enumerable  $other, callable|null$keySelector = null) : \YaLinqo\Enumerable

Produces the set difference of two sequences. The set difference of two sets is defined as the members of the first set that do not appear in the second set.

Element keys are values identifying elements. They are used as array keys and are subject to the same rules as array keys, for example, integer 100 and string "100" are considered equal.

Syntax: distinct (other)

Produces the set difference of two sequences using values as element keys.

Syntax: distinct (other, keySelector {(v, k) ==> value})

Produces the set difference of two sequences using values produced by keySelector as element keys.

#### Parameters

 array|\Iterator|\IteratorAggregate|\YaLinqo\Enumerable $other A sequence whose elements that also occur in the source sequence will cause those elements to be removed from the returned sequence. callable|null$keySelector {(v, k) ==> key} A function to extract the element key from each element. Default: value.

#### Returns

\YaLinqo\Enumerable

A sequence that contains the set difference of the elements of two sequences.

### intersect()

intersect(array|\Iterator|\IteratorAggregate|\YaLinqo\Enumerable  $other, callable|null$keySelector = null) : \YaLinqo\Enumerable

Produces the set intersection of two sequences. The intersection of two sets is defined as the set that contains all the elements of the first set that also appear in the second set, but no other elements.

Element keys are values identifying elements. They are used as array keys and are subject to the same rules as array keys, for example, integer 100 and string "100" are considered equal.

Syntax: intersect (other)

Produces the set intersection of two sequences using values as element keys.

Syntax: intersect (other, keySelector {(v, k) ==> value})

Produces the set intersection of two sequences using values produced by keySelector as element keys.

#### Parameters

 array|\Iterator|\IteratorAggregate|\YaLinqo\Enumerable $other A sequence whose distinct elements that also appear in the first sequence will be returned. callable|null$keySelector {(v, k) ==> key} A function to extract the element key from each element. Default: value.

#### Returns

\YaLinqo\Enumerable

A sequence that contains the elements that form the set intersection of two sequences.

### prepend()

prepend(mixed  $value, mixed$key = null) : \YaLinqo\Enumerable

Adds a value to the beginning of the sequence.

Syntax: prepend (other, value)

Adds a value to the beginning of the sequence with null key.

Syntax: prepend (other, value, key)

Adds a value to the beginning of the sequence with the specified key.

#### Parameters

 mixed $value The value to prepend. mixed$key The key of the value to prepend.

#### Returns

\YaLinqo\Enumerable

A new sequence that begins with the value.

### union()

union(array|\Iterator|\IteratorAggregate|\YaLinqo\Enumerable  $other, callable|null$keySelector = null) : \YaLinqo\Enumerable

Produces the set union of two sequences.

Element keys are values identifying elements. They are used as array keys and are subject to the same rules as array keys, for example, integer 100 and string "100" are considered equal.

This method excludes duplicates from the return set. This is different behavior to the \concat method, which returns all the elements in the input sequences including duplicates.

Syntax: union (other)

Produces the set union of two sequences using values as element keys.

Syntax: union (other, keySelector {(v, k) ==> value})

Produces the set union of two sequences using values produced by keySelector as element keys.

#### Parameters

 array|\Iterator|\IteratorAggregate|\YaLinqo\Enumerable $other A sequence whose distinct elements form the second set for the union. callable|null$keySelector {(v, k) ==> key} A function to extract the element key from each element. Default: value.

#### Returns

\YaLinqo\Enumerable

A sequence that contains the elements from both input sequences, excluding duplicates.

### toArray()

toArray() : array

Creates an array from a sequence.

Syntax: toArray ()

The toArray method forces immediate query evaluation and returns an array that contains the query results.

The toArray method does not traverse into elements of the sequence, only the sequence itself is converted. That is, if elements of the sequence are \Traversable or arrays containing Traversable values, they will remain as is. To traverse deeply, you can use \toArrayDeep method.

Keys from the sequence are preserved. If the source sequence contains multiple values with the same key, the result array will only contain the latter value. To discard keys, you can use \toList method. To preserve all values and keys, you can use \toLookup method.

#### Returns

array —

An array that contains the elements from the input sequence.

### toArrayDeep()

toArrayDeep() : array

Creates an array from a sequence, traversing deeply.

Syntax: toArrayDeep ()

The toArrayDeep method forces immediate query evaluation and returns an array that contains the query results.

The toArrayDeep method traverses into elements of the sequence. That is, if elements of the sequence are \Traversable or arrays containing Traversable values, they will be converted to arrays too. To convert only the sequence itself, you can use \toArray method.

Keys from the sequence are preserved. If the source sequence contains multiple values with the same key, the result array will only contain the latter value. To discard keys, you can use \toListDeep method. To preserve all values and keys, you can use \toLookup method.

#### Returns

array —

An array that contains the elements from the input sequence.

### toList()

toList() : array

Creates an array from a sequence, with sequental integer keys.

Syntax: toList ()

The toList method forces immediate query evaluation and returns an array that contains the query results.

The toList method does not traverse into elements of the sequence, only the sequence itself is converted. That is, if elements of the sequence are \Traversable or arrays containing Traversable values, they will remain as is. To traverse deeply, you can use \toListDeep method.

Keys from the sequence are discarded. To preserve keys and lose values with the same keys, you can use \toArray method. To preserve all values and keys, you can use \toLookup method.

#### Returns

array —

An array that contains the elements from the input sequence.

### toListDeep()

toListDeep() : array

Creates an array from a sequence, with sequental integer keys.

Syntax: toListDeep ()

The toListDeep method forces immediate query evaluation and returns an array that contains the query results.

The toListDeep method traverses into elements of the sequence. That is, if elements of the sequence are \Traversable or arrays containing Traversable values, they will be converted to arrays too. To convert only the sequence itself, you can use \toList method.

Keys from the sequence are discarded. To preserve keys and lose values with the same keys, you can use \toArrayDeep method. To preserve all values and keys, you can use \toLookup method.

#### Returns

array —

An array that contains the elements from the input sequence.

### toDictionary()

toDictionary(callable|null  $keySelector = null, callable|null$valueSelector = null) : array

Creates an array from a sequence according to specified key selector and value selector functions.

Syntax: toDictionary ([keySelector {(v, k) ==> key} [, valueSelector {(v, k) ==> value}]])

The toDictionary method returns an array, a one-to-one dictionary that maps keys to values. If the source sequence contains multiple values with the same key, the result array will only contain the latter value.

#### Parameters

 callable|null $keySelector {(v, k) ==> key} A function to extract a key from each element. Default: key. callable|null$valueSelector {(v, k) ==> value} A transform function to produce a result value from each element. Default: value.

#### Returns

array —

An array that contains keys and values selected from the input sequence.

### toJSON()

#### Returns

string —

A JSON encoded string on success or false on failure.

### toLookup()

toLookup(callable|null  $keySelector = null, callable|null$valueSelector = null) : array

Creates an array from a sequence according to specified key selector and value selector functions.

Syntax: toLookup ([keySelector {(v, k) ==> key} [, valueSelector {(v, k) ==> value}]])

The toLookup method returns an array, a one-to-many dictionary that maps keys to arrays of values.

#### Parameters

 callable|null $keySelector {(v, k) ==> key} A function to extract a key from each element. Default: key. callable|null$valueSelector {(v, k) ==> value} A transform function to produce a result value from each element. Default: value.

#### Returns

array —

An array that contains keys and value arrays selected from the input sequence.

### toKeys()

toKeys() : \YaLinqo\Enumerable

Returns a sequence of keys from the source sequence.

Syntax: toKeys ()

#### Returns

\YaLinqo\Enumerable

A sequence with keys from the source sequence as values and sequental integers as keys.

### toValues()

toValues() : \YaLinqo\Enumerable

Returns a sequence of values from the source sequence; keys are discarded.

Syntax: toValues ()

#### Returns

\YaLinqo\Enumerable

A sequence with the same values and sequental integers as keys.

### toObject()

toObject(callable|null  $propertySelector = null, callable|null$valueSelector = null) : \stdClass

Transform the sequence to an object.

Syntax: toObject ([propertySelector {(v, k) ==> name} [, valueSelector {(v, k) ==> value}]])

#### Parameters

 callable|null $propertySelector {(v, k) ==> name} A function to extract a property name from an element. Must return a valid PHP identifier. Default: key. callable|null$valueSelector {(v, k) ==> value} A function to extract a property value from an element. Default: value.

\stdClass

### toString()

toString(string  $separator = '', callable|null$valueSelector = null) : string

Returns a string containing a string representation of all the sequence values, with the separator string between each element.

Syntax: toString ([separator [, selector]])

#### Parameters

 string $separator A string separating values in the result string. Default: ''. callable|null$valueSelector {(v, k) ==> value} A transform function to apply to each element. Default: value.

string

### call()

#### Returns

\YaLinqo\Enumerable

The source sequence with the side-effecting behavior applied.

### write()

write(string  $separator = '', callable|null$selector = null)

Output the result of calling {@link toString} method.

Syntax: write ([separator [, selector]])

#### Parameters

 string $separator A string separating values in the result string. Default: ''. callable|null$selector {(v, k) ==> value} A transform function to apply to each element. Default: value.

string

### tryGetArrayCopy()

tryGetArrayCopy() : array|null

If the sequence wraps an array directly, return it, otherwise return null.

#### Returns

array|null —

Wrapped array, null otherwise.

### toArrayDeepProc()

#### Returns

array —

An array that contains the elements from the input sequence.

### toListDeepProc()

#### Returns

array —

An array that contains the elements from the input sequence.