- class
Flow
(php\util\Flow
) - package
std
- source
php/util/Flow.php
Description
A special class to work with arrays and iterators under flows. Flows are used for the lazy array/iterator operations, to save the RAM memory.
Class Flow, Immutable
Flow ::
ofEmpty()
Flow ::
of()
- Creates a new flow for an array of IteratorFlow ::
ofRange()
- Creates a new flow for a number rangeFlow ::
ofString()
- Creates a new flow for the stringFlow ::
ofStream()
- Creates a new flow for the Stream object
->
__construct()
- Create a new flow, you can also useof()
method->
withKeys()
- Enables to save keys for the next operation->
onlyKeys()
->
append()
- Appends a new collection to the current flow,->
anyMatch()
- Returns whether any elements of this stream match the provided->
allMatch()
- Returns whether all elements of this stream match the provided predicate.->
noneMatch()
- Returns whether no elements of this stream match the provided predicate.->
find()
- Finds elements by using the $filter callback,->
findOne()
- Finds the first element by using the $filter callback,->
findValue()
->
group()
->
each()
- Iterates elements.->
eachSlice()
- Iterates elements as slices (that are passing as arrays to $callback).->
map()
- Iterates elements and returns a new flow of the result->
keys()
- Create a new flow by using the keys of the current flow->
skip()
- Skips $n elements in the current collection->
limit()
- Limits collection with $count->
reduce()
- Iterates elements and gets a result of this operation->
max()
- Get max of elements.->
min()
- Get min of elements.->
avg()
- Get avg number of elements.->
median()
- Get median of elements.->
numMedian()
->
sum()
- Get sum of elements.->
concat()
- Get concatenation of all elements.->
sort()
- Sort the last result of the flow, also see:php\\lib\\items::sort()
->
sortByKeys()
- The same method assort()
only based on keys insteadof values->
toArray()
- Convert elements to an array->
toMap()
- Convert element to an array with keys.->
toString()
- Join elements to a string similar toimplode()
in PHP->
count()
->
current()
->
next()
->
key()
->
valid()
->
rewind()
->
__clone()
- Class is immutable, the disallowed clone method
Flow::ofEmpty(): php\util\Flow
Flow::of(iterable $collection): php\util\Flow
Creates a new flow for an array of Iterator
Flow::ofRange(int $from, int $to, int $step): php\util\Flow
Creates a new flow for a number range
Flow::ofString(string $string, int $chunkSize): php\util\Flow
Creates a new flow for the string
Flow::ofStream(php\io\Stream $stream, int $chunkSize): php\util\Flow
Creates a new flow for the Stream object
__construct(iterable $collection): void
Create a new flow, you can also use of()
method
withKeys(): php\util\Flow
Enables to save keys for the next operation
onlyKeys(iterable $keys, bool $ignoreCase): php\util\Flow
append(iterable $collection): php\util\Flow
Appends a new collection to the current flow, do not remember that you can pass a flow to this method
anyMatch(callable $predicate): bool
Returns whether any elements of this stream match the provided
predicate. May not evaluate the predicate on all elements if not
necessary for determining the result. If the flow is empty then
false
is returned and the predicate is not evaluated.
allMatch(callable $predicate): bool
Returns whether all elements of this stream match the provided predicate.
May not evaluate the predicate on all elements if not necessary for
determining the result. If the flow is empty then true
is
returned and the predicate is not evaluated.
noneMatch(callable $predicate): bool
Returns whether no elements of this stream match the provided predicate.
May not evaluate the predicate on all elements if not necessary for
determining the result. If the flow is empty then true
is
returned and the predicate is not evaluated.
find(callable $filter): php\util\Flow
Finds elements by using the $filter callback,
elements - for each iteration that returns true
findOne(callable $filter): mixed
Finds the first element by using the $filter callback,
when $filter will return the first true
findValue(mixed $value, bool $strict): int|null|string
group(callable $callback): php\util\Flow
each(callable $callback): int
Iterates elements.
It will break if $callback returns false
strongly
eachSlice(int $sliceSize, callable $callback, bool $withKeys): int
Iterates elements as slices (that are passing as arrays to $callback).
It will break if $callback returns false
strongly
map(callable $callback): php\util\Flow
Iterates elements and returns a new flow of the result Example::
$newFlow = Flow::of([1,2,3])->map(function($el){ return $el * 10 }); // the new flow will contain 10, 20 and 30
keys(): php\util\Flow
Create a new flow by using the keys of the current flow
skip(int $n): php\util\Flow
Skips $n elements in the current collection
limit(int $count): php\util\Flow
Limits collection with $count
reduce(callable $callback): int
Iterates elements and gets a result of this operation It can be used for calculate some results, for example::
// calculates a sum of elements $sum = .. ->reduce(function($result, $el){ $result = $result + $el });
max(callable|null $comparator): mixed
Get max of elements.
min(callable|null $comparator): mixed
Get min of elements.
avg(): int|float
Get avg number of elements.
median(callable|null $comparator): mixed
Get median of elements.
numMedian(callable|null $comparator): int|float
sum(): int|float
Get sum of elements.
concat(): string
Get concatenation of all elements.
sort(callable $comparator): array
Sort the last result of the flow, also see: php\\lib\\items::sort()
.. note:: use the withKeys()
method to save keys
sortByKeys(callable $comparator): array
The same method as sort()
only based on keys insteadof values
.. note:: use the withKeys()
method to save keys
toArray([ bool|null $withKeys): array
Convert elements to an array
.. note:: use the withKeys()
method to save keys
toMap(): array
Convert element to an array with keys.
toString(string $separator): string
Join elements to a string similar to implode()
in PHP
count(): int
current(): mixed
next(): void
key(): mixed
valid(): bool
rewind(): void
__clone(): void
Class is immutable, the disallowed clone method