Download the PHP package mkrawczyk/funquery without Composer
On this page you can find all versions of the php package mkrawczyk/funquery. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download mkrawczyk/funquery
More information about mkrawczyk/funquery
Files in mkrawczyk/funquery
Package funquery
Short Description Functional programming library for PHP
License MIT
Informations about the package funquery
This lib allows you to make operations on arrays in functional style. It is like LINQ, but for PHP.
Designed for PHP 7.4 and higher.
Installation
Example
``
Result can be used as iterator, or converted to Array ``
Like LINQ, it uses lazy execution ``
methods
FunQuery::create(array|IteratorAggregateNode|IteratorNode|FunQuery $init)
Creates FunQuery object from array, generator or iterator.
filter(callable(T):bool $fun)
Executes function for every item and sends to output only, if function returns true
sort(...$funs)
Sorts items. If function is passed, it sorts by result of this function
map(callable(T):T2 $fun)
It keeps the same number of items, but each item is replaced by what was returned by passed function.
first()
Returns first object. Throws exception if pipeline is empty.
firstOrNull()
Returns first object or null if pipeline is empty.
skip(int $count = 0)
Skips first $count items.
limit(?int $limit = null)
Limits number of items to $limit. If $limit is null, it will return all items.
slice(int $skip = 0, ?int $limit = null)
Combines skip and limit. It skips $skip items and limits to $limit items.
flat()
Flattens array of arrays.
distinct(callable(T):T2 $fun=null)
Removes duplicates. If function is passed, it will compare results of this function.
toArray()
Converts FunQuery to array.
toAssoc(callable(T):string $keyFun, callable(T):T2 $valueFun)
Converts FunQuery to associative array. If there are duplicates, it will throw exception.
toAssocArrayIgnoreDuplicates(callable(T):string $keyFun, callable(T):T2 $valueFun)
Converts FunQuery to associative array. If there are duplicates, it will ignore them.
some(callable(T):bool $fun)
Returns true if at least one item matches condition.
every(callable(T):bool $fun)
Returns true if all items match condition.
count()
Returns number of items.
reduce(callable(T,T):T $fun, T $initial)
Reduces items to single value.
groupBy(callable(T):T2 $fun)
Groups items by result of function.
reverse()
Reverses items.
execute()
Executes pipeline. By default FunQuery uses lazy execution, but sometimes you may want to force execution.
min(callable(T):T2 $fun)
Returns minimal value. If function is passed, it will compare results of this function, but returns original value.
max(callable(T):T2 $fun)
Returns maximal value. If function is passed, it will compare results of this function, but returns original value.
sum(callable(T):T2 $fun)
Returns sum of values. If function is passed, it will sum results of this function.
avg(callable(T):T2 $fun)
Returns average of values. If function is passed, it will average results of this function.
concat(FunQuery $funQuery)
Concatenates two FunQuery objects.
All versions of funquery with dependencies
ext-json Version *