Download the PHP package miroshnikov/idles without Composer
On this page you can find all versions of the php package miroshnikov/idles. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download miroshnikov/idles
More information about miroshnikov/idles
Files in miroshnikov/idles
Package idles
Short Description A PHP functional utility library, port of Lodash/Ramda with lazy (idle) evaluation
License MIT
Homepage https://miroshnikov.github.io/idles/
Informations about the package idles
IDLES - a PHP functional library
A PHP functional utility library, port of Javascript Lodash/Fp and Ramda libraries to PHP.
All functions are side-effect free and automatically curried, data is immutable.
The iterable collection parameter is usually supplied last to make currying convenient.
Lazy / delayed evaluation is supported in functional pipelines.
Go to https://idlephp.tech for more details, documentation and examples.
Requirements
PHP 7.4
or higher
Installation
composer require miroshnikov/idles
Roadmap
[!NOTE]
Idles is currently under active development. Roadmap is to add all methods from Lodash and Ramda libraries and some functional tools.
Documentation
Array
concat
Concatinates $array
with additional iterables/values
count
Counts the number of items in $collection
matching the $predicate
countBy
Returns an array: [$iteratee($value)
=> number of times the $iteratee($value)
was found in $collection
]
drop
Skips the first $n
elemens and returns the rest of the iterable
dropRight
Skips the last $n
elements
findIndex
Like find
but returns the index of the first element predicate returns truthy for, -1
if not found
findLastIndex
Like find
but returns the index of the last element predicate returns truthy for, -1
if not found
flatten
Flattens iterable a single level deep.
flattenDeep
Recursively flattens iterable.
flattenDepth
Recursively flatten array up to depth times.
fromPairs
Creates a new record from a list key-value pairs. The inverse of toPairs
.
head
Gets the first element of iterable
indexOf
Returns the index of the first occurrence of $value
in $collection
, else -1.
intersection
Returns unique values that are included in both records
intersectionBy
Like intersection
but invokes $iteratee
for each element before comparison.
intersectionWith
Like intersection
but invokes $comparator
to compare elements.
join
Joins iterable elements separated by $separator
last
Gets the last element of iterable
nth
Returns the $offset
element. If $offset
is negative the element at index length + $offset
is returned.
remove
Removes items from $iterable
starting at $start
and containing $count
elements.
slice
Retruns a slice of $iterable
from $start
up to, but not including, $end
.
take
Takes n first elements from iterable
takeRight
Returns a slice of iterable with n elements taken from the end.
uniq
Removes duplicates using ===
uniqueBy
Like uniq
but apply $iteratee
fist
uniqWith
Like uniq
but uses $predicate
to compare elements
without
Returns $iterable
without $values
zip
Creates an iterable of grouped elements, the first of which contains the first elements of the given iterables, the second of which contains the second elements, and so on.
zipWith
Like zip
except that it accepts $iteratee
to specify how grouped values should be combined.
Collection
all
Checks if $predicate
returns truthy
for all elements of $collection
. Stop once it returns falsey
any
Checks if $predicate
returns truthy for any element of $collection
. Stops on first found.
each
Iterates over elements of $collection
. Iteratee may exit iteration early by returning false
.
filter
Returns elements $predicate
returns truthy for.
find
Returns the first element $predicate
returns truthy for.
flatMap
Maps then flatten
flatMapDeep
Like flatMap
but recursively flattens the results.
flatMapDepth
Like flatMap
but flattens the mapped results up to $depth
times
groupBy
Creates an array composed of keys generated from running each value through $iteratee
.
includes
Checks if $value
is in $collection
.
indexBy
Creates a record composed of keys generated from the results of running each element of $collection
through $iteratee
.
map
Run each element in $collection
through $iteratee
.
orderBy
Like sortBy
but allows specifying the sort orders
partition
Split $collection
into two groups, the first of which contains elements $predicate
returns truthy for, the second of which contains elements $predicate
returns falsey for.
reduce
Reduces $collection
to a value which is the accumulated result of running each element in collection through $iteratee
resolve
Adds new properties to $record
using $resolvers
.
sort
Sorts $collection
using $comparator
comparison ($a <=> $b
) function
sortBy
Sorts $collection
in ascending order according to $comparators
.
sortWith
Sorts a $collection
according to an array of comparison ($a <=> $b
) functions
values
Returns an indexed iterable of values in $collection
.
Function
always
Returns a function that always returns the given value.
applyTo
Returns $interceptor($value)
.
ary
Creates a function that invokes $fn
, with up to $n
arguments, ignoring any additional arguments.
ascend
Makes an ascending comparator function out of a function that returns a value that can be compared with <=>
attempt
Calls $fn
, returning either the result or the caught exception.
compose
Like pipe
but invokes the functions from right to left.
curry
\Idles\_
const may be used as a placeholder.
curryRight
Like curry
but arguments are prepended.
descend
Makes an descending comparator function out of a function that returns a value that can be compared with <=>
flip
Returns a new curried function with the first two arguments reversed
juxt
Applies a list of functions to a list of values.
memoize
Creates a function that memoizes the result of $func
. $resolver
returns map cache key, args[0] by default.
negate
Creates a function that negates the result of the $predicate
function.
once
$fn
is only called once, the first value is returned in subsequent invocations.
partial
Creates a function that invokes $fn
with $partials
prepended to the arguments. \Idles\_
const may be used as a placeholder.
partialRight
Like partial
but $partials
are appended.
pipe
Left-to-right function composition. The first argument may have any arity; the remaining arguments must be unary.
tap
Calls $interceptor($value)
then returns the original $value
times
Calls the iteratee $n
times, returning an array of the results of each invocation.
tryCatch
Calls $tryer
, if it throws, calls $catcher
unary
ary(1, $fn)
Logic
allPass
Returns a function that checks if its arguments pass all $predicates
.
anyPass
Returns a function that checks if its arguments pass any of the $predicates
.
both
Resulting function returns $func1(...$args)
if it is falsy or $func2(...$args)
otherwise, short-circuited
cond
Iterates over $pairs
and invokes the corresponding function of the first predicate to return truthy.
defaultTo
Returns $value
?? $default
either
Resulting function returns $func1(...$args)
if it is truthy or $func2(...$args)
otherwise, short-circuited.
ifElse
Resulting function returns $onTrue(...$args)
if $predicate(...$args)
is truthy or $onFalse(...$args)
otherwise.
not
returns !$a
unless
Returns $predicate($value) ? $value : $whenFalse($value)
when
Returns $predicate($value) ? $whenTrue($value) : $value
Math
add
$a + $b
dec
Returns $number - 1
divide
$a / $b
gt
$a > $b
gte
$a >= $b
inc
Returns $number + 1
lt
$a < $b
lte
$a <= $b
modulo
$a % $b
multiply
$a * $b
round
Rounds $number
to specified $precision
subtract
$a - $b
sum
Sums elements in iterable
sumBy
Like sum
but $iteratee
is invoked for each element in iterable to generate the value to be summed.
Record
assignDeep
Merges properties recursively, numeric keys are overwritten.
defaults
Merges properties from right to left, numeric keys are overwritten.
evolve
Creates a new record by recursively calling transformation functions with $record
properties.
extend
Merges properties, numeric keys are overwritten.
has
Checks if $record
has $key
hasPath
Checks if $path
exists in $record
invert
Replaces keys with values. Duplicate keys are overwritten.
keys
Returns an indexed iterable of keys in $record
.
merge
Merges properties, numeric keys are appended.
mergeDeep
Merges properties recursively, numeric keys are appended.
mergeLeft
calls merge($right, $left)
mergeWith
Like merge
but if a key exists in both records, $customizer
is called to the values associated with the key
modifyPath
Creates new record by applying an $updater
function to the value at the given $path
.
objOf
Creates an array
containing a single key => value pair.
omit
The opposite of pick
. Returns record without $keys
.
omitBy
The opposite of pickBy
. Returns properties of $record
that $predicate
returns falsey for.
path
Retrieve the value at a given path.
paths
Keys in, values out. Order is preserved.
pick
Returns record containing only $keys
pickBy
Returns record containing only keys $predicate
returns truthy for.
pluck
Returns a new array by plucking the same named property off all records in the array supplied.
prop
Return the specified property.
propEq
Returns $record[$key] == $value
setPath
Return copy $record
with $path
set with $value
toPairs
Converts a record into an array of [$key, $value]
where
Checks if $record
satisfies the spec by invoking the $spec
properties with the corresponding properties of $record
.
whereAny
Checks if $record
satisfies the spec by invoking the $spec
properties with the corresponding properties of $record
. Returns true
if at least one of the predicates returns true
.
whereEq
Check if the $test
satisfies the $spec
String
escape
Converts the characters "&", "<", ">", '"', and "'" to their corresponding HTML entities.
escapeRegExp
Escapes regular expression
split
Splits string by $separator
.
startsWith
If string starts with $target
.
toLower
Converts string to lower case
toUpper
Converts string to upper case
words
Splits string into an array of its words.
Util
collect
Collects any iterable into array
eq
$a
== $b
equals
$a
=== $b
F
Always returns false
identity
Returns the first argument it receives.
iterate
Returns a generator of $value
, $f($value)
, $f($f($value))
etc.
just
Returns an Optional with the specified non-null value
nothing
Returns an empty Optional
now
Returns the timestamp of the number of seconds
Optional
Maybe/Option monad (container) which may or may not contain a non-null value. Has methods:
isPresent(): bool
- true
if not empty
isEmpty(): bool
- true
if empty
get(): mixed
- returns value, throw exception if empty
orElse(mixed $default): mixed
- returns the contained value if the optional is nonempty or $default
orElseThrow(Exception $e)
- returns the contained value, if present, otherwise throw an exception
map(callable $f): Optional
- If a value is present, apply the $f
to it, and if the result is non-null, return an Optional describing the result
flatMap(callable $f): Optional
- use instead of map
if $f
returns Optional
filter(callable $predicate): Optional
- if a value is present and matches the $predicate
, return an Optional with the value, otherwise an empty Optional.
size
Returns size of a countable, number of parameters of a function, lenght of string or number of properties of an object
T
Always returns true