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 8.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
add
Calculates the sum of two numbers.
adjust
Applies a function to the value at the given key of an array.
all
Checks if $predicate returns truthy for all elements of $collection. Stop once it returns falsey.
allPass
Returns a function that checks if its arguments pass all $predicates.
always
Returns a function that always returns the given value.
any
Checks if $predicate returns truthy for any element of $collection. Stops on first found.
anyPass
Returns a function that checks if its arguments pass any of the $predicates.
apply
Calls $fn(...$args).
applyTo
Returns the result of $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.
both
Resulting function returns $fn1(...$args) if it is falsy or $fn2(...$args) otherwise, short-circuited.
call
Calls $fn(...$args).
camelCase
Converts string to camel case.
capitalize
Converts the first character of string to upper case and the remaining to lower case.
collect
Collects any iterable into array
compose
Like pipe but invokes the functions from right to left.
concat
Concatinates an iterable with an iterable/value.
concatAll
Concatinates an iterable with additional iterables/values
cond
Iterates over $pairs and invokes the corresponding function of the first predicate to return truthy.
converge
Resulting function will call each function with input arguments and pass results to $afterFn.
count
Counts the number of items in $collection matching the $predicate
countBy
Returns an array<result of $iteratee($value), number of times the $iteratee($value) was found in $collection>
curry
\Idles\_ const may be used as a placeholder.
curryN
Curry with fixed arity. \Idles\_ const may be used as a placeholder.
curryRight
Like curry but arguments are prepended.
curryRightN
Like curryN but arguments are prepended.
dec
Returns $number - 1
defaultTo
Returns $value if it is truthy, otherwise $default.
descend
Makes an descending comparator function out of a function that returns a value that can be compared with <=>.
divide
Returns $a / $b
drop
Skips the first $n elemens and returns the rest of iterable or string.
dropLast
Skips the last $n elements of iterable or string.
each
Iterates over elements of $collection. Iteratee may exit iteration early by returning false.
either
Resulting function returns $fn1(...$args) if it is truthy or $fn2(...$args) otherwise, short-circuited.
eq
$a == $b
equals
$a === $b
escapeRegExp
Escapes regular expression.
evolve
Creates a new record by recursively calling transformation functions with $record properties.
F
Always returns false
filter
Returns elements $predicate returns truthy for.
find
Returns the first element $predicate returns truthy for.
findFrom
Returns the first element $predicate returns truthy for starting from $fromIndex.
findIndex
Returns the index of the first element predicate returns truthy for or -1 if not found.
findIndexFrom
Returns the index of the first element $predicate returns truthy for starting from $fromIndex.
findLastIndex
Returns the index of the last element predicate returns truthy for, -1 if not found.
findLastIndexFrom
Returns the index of the last element $predicate returns truthy for starting from $fromIndex.
flatMap
Maps and flattens.
flatMapDepth
Maps and flattens the mapped results up to $depth times.
flatten
Flattens iterable a single level deep.
flattenDepth
Recursively flatten array up to $depth times.
flip
Returns a new curried function with the first two arguments reversed.
flow
Left-to-right function composition. The first argument may have any arity; the remaining arguments must be unary.
fromPairs
Creates a new record from a list key-value pairs. The inverse of toPairs.
groupBy
Creates an array composed of keys generated from running each value through $iteratee.
gt
$a > $b
gte
$a >= $b
has
Checks if $record has $key by calling array_key_exists().
hasPath
Checks if $path exists in $record.
head
Gets the first element of $collecton.
identity
Returns the first argument it receives.
ifElse
Resulting function returns $onTrue(...$args) if $predicate(...$args) is truthy or $onFalse(...$args) otherwise.
inc
Returns $number + 1
includes
Checks if $value is in iterable/string.
includesFrom
Checks if $value is in iterable/string, starting from $fromIndex.
indexBy
Creates a record composed of keys generated from the results of running each element of $collection through $iteratee.
indexOf
Returns the index of the first occurrence of the item in an iterable or string, else -1.
indexOfFrom
Returns the index of the first occurrence of the item in an iterable or string, starting from $fromIndex, else -1.
insert
Inserts the $element at the specified $index.
intersection
Returns unique values that are included in both arrays.
intersectionBy
Like intersection but invokes $iteratee for each element before comparison.
intersectionWith
Like intersection but invokes $comparator to compare elements.
invert
Replaces keys with values. Duplicate keys are overwritten.
isEmpty
Returns result of empty($value).
isNotEmpty
Returns result of !empty($value).
iterate
Returns a generator of $value, $f($value), $f($f($value)) etc.
join
Joins iterable elements separated by $separator.
just
Returns an Optional with the specified non-null value
juxt
Applies a list of functions to a list of values.
kebabCase
Converts string to kebab case.
keys
Returns an indexed iterable of keys in $record.
last
Gets the last element of iterable.
lastIndexOf
Returns the index of the last occurrence of $value in iterable or string, else -1.
length
Returns size of a countable, number of parameters of a function, lenght of string or number of properties of an object.
lowerFirst
Converts the first character of string to lower case.
lt
$a < $b
lte
$a <= $b
map
Run each element in $collection through $iteratee.
mapKeys
Transforms an object by converting the keys to new values.
memoize
Creates a function that memoizes the result of $fn.
memoizeWith
Creates a function that memoizes the result of $fn. $resolver returns map cache key (args[0] by default).
merge
Merges properties, numeric keys are replaced.
mergeAll
Merges properties, numeric keys are replaced.
mergeDeep
Merges properties recursively, numeric keys are replaced.
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.
modulo
$a % $b
multiply
$a * $b
negate
Creates a function that negates the result of the $predicate function.
not
returns !$a
nothing
Returns an empty Optional.
now
Returns the timestamp of the number of seconds
nth
Returns the $offset element. If $offset is negative the element at index length + $offset is returned.
nthArg
Returns a function which returns its $nth argument.
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.
once
$fn is only called once, the first value is returned in subsequent invocations.
Optional
Maybe/Option monad (container) which may or may not contain a non-null value.
orderBy
Like sortBy but allows specifying the sort orders.
pad
Pad a string on the left and right sides to a certain length with padding characters.
padEnd
Pad a string on the right side to a certain length with padding characters.
padStart
Pad a string on the left side to a certain length with padding characters.
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.
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.
path
Retrieve the value at a given path.
pathEq
If a record has a $value at $path in equals() terms.
pathOr
Retrieve the value at a given path. If path is not found, the $default is returned.
paths
Keys in, values out. Order is preserved.
pick
Returns record containing only $keys.
pickBy
Returns record containing only keys $predicate returns truthy for.
pipe
Left-to-right function composition. The first argument may have any arity; the remaining arguments must be unary.
pluck
Returns a new array by plucking the same named property off all records in the array supplied.
project
Like SQL select statement.
prop
Return the specified property.
propEq
Returns $record[$key] == $value
propOr
Return the $key property or $default.
propSatisfies
Returns $predicate($record[$key])
rearg
Returns a curried function that invokes $fn with arguments rearranged according to $indexes.
rebuild
Transforms an object into a new one, applying to every key-value pair a function creating zero, one, or many new key-value pairs, and combining the results into a single object.
reduce
Reduces $collection to a value which is the accumulated result of running each element in collection through $iteratee.
remove
Removes items from $iterable starting at $start and containing $count elements.
renameKeys
Converts an object to a new one by changing all keys that are also found as keys in a mapping object to their corresponding values from that object.
replace
Replace a regex match in a string with a replacement.
resolve
Adds new properties to $record using $resolvers.
round
Rounds $number to specified $precision
setPath
Return copy of $record with $path set with $value.
slice
Returns a slice of iterable or string from $start up to, but not including $end.
snakeCase
Converts string to snake case.
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.
split
Splits string by $separator regular expression.
splitAt
Splits a given array or string at a given index.
splitEvery
Splits an array or string into slices of the specified length.
splitWhen
Splits an array by predicate.
splitWhenever
Splits an array into slices on every occurrence of a value.
startsWith
If string starts with $target.
subtract
$a - $b
sum
Sums elements in $collection
sumBy
Sums elements, $iteratee is invoked for each element in $collection to generate the value to be summed.
T
Always returns true
tail
Returns all but the first element of the iterable or string.
take
Takes $n first elements from iterable.
takeLast
Returns a slice of iterable with $n elements taken from the end.
tap
Calls $interceptor($value) then returns the original $value.
times
Calls the iteratee $n times, returning an array of the results of each invocation.
toLower
Converts string to lower case.
toPairs
Converts a record into an array of [$key, $value].
toUpper
Converts string to upper case.
trim
Strip characters from the beginning and end of a string.
trimEnd
Strip characters from the end of a string.
trimStart
Strip characters from the beginning of a string.
tryCatch
Calls $tryer, if it throws, calls $catcher.
unapply
Returns fn (...$args) => $fn($args)
unary
ary(1, $fn)
uniq
Removes duplicates using ===.
uniqBy
Like uniq but apply $iteratee fist.
uniqWith
Like uniq but uses $predicate to compare elements.
unless
Returns $predicate($value) ? $value : $whenFalse($value).
update
Returns a new copy of the array with the element at the provided index replaced with the given value.
upperFirst
Converts the first character of string to upper case.
useWith
Applies each transformer function to each argument. Returns a new curried functions.
values
Returns an indexed iterable of values in $collection.
when
Returns $predicate($value) ? $whenTrue($value) : $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.
without
Returns $iterable without $values.
words
Splits string into an array of words.
zip
Creates a new iterable out of the two supplied by pairing up equally-positioned items from both iterables.
zipAll
Same as zip but for many iterables.
zipWith
Like zip except that it accepts $iteratee to specify how grouped values should be combined.