\YaLinqoEnumerableGeneration

Trait of {@link Enumerable} containing generation methods.

Summary

Methods
Properties
Constants
cycle()
emptyEnum()
from()
generate()
toInfinity()
matches()
toNegativeInfinity()
returnEnum()
range()
rangeDown()
rangeTo()
repeat()
split()
No public properties found
No constants found
No protected methods found
No protected properties found
N/A
No private methods found
No private properties found
N/A

Methods

cycle()

cycle(array|\Iterator|\IteratorAggregate|\YaLinqo\Enumerable  $source) : \YaLinqo\Enumerable

Cycles through the source sequence.

Syntax: cycle (source)

Source keys are discarded.

Parameters

array|\Iterator|\IteratorAggregate|\YaLinqo\Enumerable $source

Source sequence.

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

from(array|\Iterator|\IteratorAggregate|\Traversable|\YaLinqo\Enumerable  $source) : \YaLinqo\Enumerable

Converts source into Enumerable sequence.

Syntax: from (source)

Result depends on the type of source:

  • array: Enumerable from ArrayIterator;
  • Enumerable: Enumerable source itself;
  • Iterator: Enumerable from Iterator;
  • IteratorAggregate: Enumerable from Iterator returned from getIterator() method;
  • Traversable: Enumerable from the result of foreach over source.

Parameters

array|\Iterator|\IteratorAggregate|\Traversable|\YaLinqo\Enumerable $source

Value to convert into Enumerable sequence.

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

matches(string  $subject, string  $pattern, integer  $flags = PREG_SET_ORDER) : \YaLinqo\Enumerable

Searches subject for all matches to the regular expression given in pattern and enumerates them in the order specified by flags. After the first match is found, the subsequent searches are continued on from end of the last match.

Syntax: matches (subject, pattern [, flags])

Parameters

string $subject

The input string.

string $pattern

The pattern to search for, as a string.

integer $flags

Can be a combination of the following flags: PREG_PATTERN_ORDER, PREG_SET_ORDER, PREG_OFFSET_CAPTURE. Default: PREG_SET_ORDER.

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

returnEnum(mixed  $element) : \YaLinqo\Enumerable

Returns a sequence that contains a single element with a specified value.

Syntax: returnEnum (element)

Parameters

mixed $element

The single element in the resulting sequence.

Returns

\YaLinqo\Enumerable

Observable sequence containing the single specified element.

range()

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

Generates a sequence of integral numbers, beginning with start and containing count elements.

Syntax: range (start, count [, step])

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

Example: range(3, 4, 2) = 3, 5, 7, 9.

Parameters

integer $start

The value of the first integer in the sequence.

integer $count

The number of integers to generate.

integer $step

The difference between adjacent integers. Default: 1.

Returns

\YaLinqo\Enumerable

A sequence that contains a range of integral numbers.

rangeDown()

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

Generates a reversed sequence of integral numbers, beginning with start and containing count elements.

Syntax: rangeDown (start, count [, step])

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

Example: rangeDown(9, 4, 2) = 9, 7, 5, 3.

Parameters

integer $start

The value of the first integer in the sequence.

integer $count

The number of integers to generate.

integer $step

The difference between adjacent integers. Default: 1.

Returns

\YaLinqo\Enumerable

A sequence that contains a range of integral numbers.

rangeTo()

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

Generates a sequence of integral numbers within a specified range from start to end.

Syntax: rangeTo (start, end [, step])

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

Example: rangeTo(3, 9, 2) = 3, 5, 7, 9.

Parameters

integer $start

The value of the first integer in the sequence.

integer $end

The value of the last integer in the sequence (not included).

integer $step

The difference between adjacent integers. Default: 1.

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

split(string  $subject, string  $pattern, integer  $flags) : \YaLinqo\Enumerable

Split the given string by a regular expression.

Syntax: split (subject, pattern [, flags])

Parameters

string $subject

The input string.

string $pattern

The pattern to search for, as a string.

integer $flags

flags can be any combination of the following flags: PREG_SPLIT_NO_EMPTY, PREG_SPLIT_DELIM_CAPTURE, PREG_SPLIT_OFFSET_CAPTURE. Default: 0.

Returns

\YaLinqo\Enumerable