PHP Trait YaLinqo\EnumerableGeneration

Show file Open project: athari/yalinqo

Public Methods

Method Description
cycle ( array | Iterator | IteratorAggregate | Enumerable $source ) : Enumerable Cycles through the source sequence.
emptyEnum ( ) : Enumerable Returns an empty sequence.
from ( array | Iterator | IteratorAggregate | Traversable | Enumerable $source ) : Enumerable Converts source into Enumerable sequence.
generate ( callable $funcValue, mixed $seedValue = null, callable | null $funcKey = null, mixed $seedKey = null ) : Enumerable Generates a sequence by mimicking a for loop.
matches ( string $subject, string $pattern, integer $flags = PREG_SET_ORDER ) : 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.
range ( integer $start, integer $count, integer $step = 1 ) : Enumerable Generates a sequence of integral numbers, beginning with start and containing count elements.
rangeDown ( integer $start, integer $count, integer $step = 1 ) : Enumerable Generates a reversed sequence of integral numbers, beginning with start and containing count elements.
rangeTo ( integer $start, integer $end, integer $step = 1 ) : Enumerable Generates a sequence of integral numbers within a specified range from start to end.
repeat ( integer $element, integer $count = null ) : Enumerable Generates an sequence that contains one repeated value.
returnEnum ( mixed $element ) : Enumerable Returns a sequence that contains a single element with a specified value.
split ( string $subject, string $pattern, integer $flags ) : Enumerable Split the given string by a regular expression.
toInfinity ( integer $start, integer $step = 1 ) : Enumerable Generates a sequence of integral numbers to infinity.
toNegativeInfinity ( integer $start, integer $step = 1 ) : Enumerable Generates a sequence of integral numbers to negative infinity.

Private Methods

Method Description
fromTraversable ( $source )

Method Details

cycle() public static method

Syntax: cycle (source)

Source keys are discarded.

public static cycle ( array | Iterator | IteratorAggregate | Enumerable $source ) : Enumerable
$source array | Iterator | IteratorAggregate | Enumerable Source sequence.
return Enumerable Endless list of items repeating the source sequence.

emptyEnum() public static method

Syntax: emptyEnum ()

public static emptyEnum ( ) : Enumerable
return Enumerable

from() public static method

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.
public static from ( array | Iterator | IteratorAggregate | Traversable | Enumerable $source ) : Enumerable
$source array | Iterator | IteratorAggregate | Traversable | Enumerable Value to convert into Enumerable sequence.
return Enumerable

generate() public static method

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.

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

matches() public static method

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

See also: preg_match_all
public static matches ( string $subject, string $pattern, integer $flags = PREG_SET_ORDER ) : Enumerable
$subject string The input string.
$pattern string The pattern to search for, as a string.
$flags integer Can be a combination of the following flags: PREG_PATTERN_ORDER, PREG_SET_ORDER, PREG_OFFSET_CAPTURE. Default: PREG_SET_ORDER.
return Enumerable

range() public static method

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.

public static range ( integer $start, integer $count, integer $step = 1 ) : Enumerable
$start integer The value of the first integer in the sequence.
$count integer The number of integers to generate.
$step integer The difference between adjacent integers. Default: 1.
return Enumerable A sequence that contains a range of integral numbers.

rangeDown() public static method

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.

public static rangeDown ( integer $start, integer $count, integer $step = 1 ) : Enumerable
$start integer The value of the first integer in the sequence.
$count integer The number of integers to generate.
$step integer The difference between adjacent integers. Default: 1.
return Enumerable A sequence that contains a range of integral numbers.

rangeTo() public static method

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.

public static rangeTo ( integer $start, integer $end, integer $step = 1 ) : Enumerable
$start integer The value of the first integer in the sequence.
$end integer The value of the last integer in the sequence (not included).
$step integer The difference between adjacent integers. Default: 1.
return Enumerable A sequence that contains a range of integral numbers.

repeat() public static method

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.

public static repeat ( integer $element, integer $count = null ) : Enumerable
$element integer The value to be repeated.
$count integer The number of times to repeat the value in the generated sequence. Default: null.
return Enumerable A sequence that contains a repeated value.

returnEnum() public static method

Syntax: returnEnum (element)

public static returnEnum ( mixed $element ) : Enumerable
$element mixed The single element in the resulting sequence.
return Enumerable Observable sequence containing the single specified element.

split() public static method

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

See also: preg_split
public static split ( string $subject, string $pattern, integer $flags ) : Enumerable
$subject string The input string.
$pattern string The pattern to search for, as a string.
$flags integer flags can be any combination of the following flags: PREG_SPLIT_NO_EMPTY, PREG_SPLIT_DELIM_CAPTURE, PREG_SPLIT_OFFSET_CAPTURE. Default: 0.
return Enumerable

toInfinity() public static method

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

public static toInfinity ( integer $start, integer $step = 1 ) : Enumerable
$start integer The first integer in the sequence. Default: 0.
$step integer The difference between adjacent integers. Default: 1.
return Enumerable

toNegativeInfinity() public static method

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

public static toNegativeInfinity ( integer $start, integer $step = 1 ) : Enumerable
$start integer The first integer in the sequence. Default: 0.
$step integer The difference between adjacent integers. Default: 1.
return Enumerable