PHP Trait YaLinqo\EnumerableGeneration

Afficher le fichier Open project: athari/yalinqo

Méthodes publiques

Méthode 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

Méthode Description
fromTraversable ( $source )

Method Details

cycle() public static méthode

Syntax: cycle (source)

Source keys are discarded.

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

emptyEnum() public static méthode

Syntax: emptyEnum ()

public static emptyEnum ( ) : Enumerable
Résultat Enumerable

from() public static méthode

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

generate() public static méthode

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

matches() public static méthode

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

range() public static méthode

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.
Résultat Enumerable A sequence that contains a range of integral numbers.

rangeDown() public static méthode

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.
Résultat Enumerable A sequence that contains a range of integral numbers.

rangeTo() public static méthode

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.
Résultat Enumerable A sequence that contains a range of integral numbers.

repeat() public static méthode

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.
Résultat Enumerable A sequence that contains a repeated value.

returnEnum() public static méthode

Syntax: returnEnum (element)

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

split() public static méthode

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

toInfinity() public static méthode

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

toNegativeInfinity() public static méthode

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