
PHP功能库库,JavaScript Lodash/fp的港口和ramda库的PHP。
所有功能都是无副作用的,并且自动咖喱,数据是不可变的。
通常提供的含量收集参数是使咖喱方便的。
功能管道中支持懒惰 /延迟评估。
有关更多详细信息,文档和示例,请访问https://idlephp.tech 。
PHP 7.4或更高
composer require miroshnikov/idles
笔记
IDLE目前正在积极发展。路线图将添加来自Lodash和Ramda库中的所有方法以及一些功能工具。
concat(?iterable $ array, $ value ): iterable将$array与其他迭代/值串联
count(callable $ predicate , ?iterable $ collection ): int计算与$ $predicate $collection中的项目数
countBy(callable $ iteratee , ?iterable $ collection ): array返回一个数组:[ $iteratee($value) => $iteratee($value)次数在$collection中找到]
drop(int $ n , ?iterable $ collection ): iterable跳过第一个$n Elemens,然后返回其余的东西
dropRight(int $ n , ?iterable $ collection ): iterable跳过最后的$n元素
findIndex(callable $ predicate , ?iterable $ collection ): int像find但返回第一个元素谓词的索引返回真相, -1如果找不到的话
findLastIndex(callable $ predicate , ?iterable $ collection ): int像find但返回最后一个元素谓词的索引返回真相, -1如果找不到的话
flatten(?iterable $ collection ): iterable使一个层次的深度扁平化。
flattenDeep(?iterable $ collection ): iterable递归使具有凹陷的效果。
flattenDepth(int $ depth , ?iterable $ collection ): iterable递归使阵列直至深度时间。
fromPairs(?iterable $ collection ): array从列表键值对创建新记录。 toPairs的倒数。
head(?iterable $ collecton )获取峰值的第一个元素
indexOf( $ value , ?iterable $ collection ): int返回第一次出现$value $collection的索引,else -1。
intersection(?iterable $ record1 , ?iterable $ record2 ): array返回两个记录中包含的唯一值
intersectionBy(callable $ iteratee , ?iterable $ record1 , ?iterable $ record2 ): array像intersection一样,但在比较之前为每个元素调用$iteratee 。
intersectionWith(callable $ comparator , ?iterable $ record1 , ?iterable $ record2 ): array像intersection一样,但调用$comparator比较元素。
join(string $ separator , ?iterable $ collection ): string加入由$separator分隔的迭代元素
last(?iterable $ collecton )获取峰值的最后一个元素
nth (int $ offset , ?iterable $ collection )返回$offset元素。如果$offset为负,则返回索引长度 + $offset元素。
remove(int $ start , int $ count , ?iterable $ iterable ): array从$start开始并包含$count元素中删除$iterable的项目。
slice(int $ start , int ? $ end , ?iterable $ collection ): iterable从$start到但不包括$end的$iterable itoser来重新返回。
take(int $ n , ?iterable $ collection ): iterable从Itable中获取n个第一元素
takeRight(int $ n , ?iterable $ collection ): array返回一小部分,其中n个元素从末尾取。
uniq(?iterable $ collection ): array使用===删除重复项
uniqBy(callable $ iteratee , ?iterable $ collection ): array像uniq一样,但施加$iteratee拳头
uniqWith(callable $ predicate , ?iterable $ collection ): array像uniq一样,但使用$predicate比较元素
without(array $ values , ?iterable $ collection ): iterable返回$iterable没有$values
zip (iterable $ a , iterable $ b ): iterable创建一个分组元素的尤其是其中的第一个元素,其中包含给定迭代的第一个元素,其中第二个包含第二个元素,依此类推。
zipWith (callable $ iteratee , iterable $ a , iterable $ b ): iterable像zip一样,除了它接受$iteratee以指定应如何组合分组值。
all(?callable $ predicate , ?iterable $ collection ): bool检查$predicate是否返回$collection的所有元素的truthy 。一旦返回falsey
any(callable $ predicate , ?iterable $ collection ): bool检查$predicate是否返回$collection的任何元素。首先找到。
each(callable $ iteratee , ?iterable $ collection ): iterable迭代$collection的元素。 ITEMERE可以通过返回false提早退出迭代。
filter(callable $ predicate , ?iterable $ collection ): iterable返回元素$predicate返回真相。
find(?callable $ predicate , ?iterable $ collection )返回第一个元素$predicate返回真相。
flatMap(callable $ iteratee , ?iterable $ collection ): iterable然后地图变平
flatMapDeep(callable $ iteratee , ?iterable $ collection ): iterable像flatMap一样,但会递归地弄平结果。
flatMapDepth(callable $ iteratee , int $ depth , ?iterable $ collection ): iterable像flatMap一样,但使映射结果达到$depth时间
groupBy(callable $ iteratee , ?iterable $ collection ): array创建一个由从运行每个值通过$iteratee生成的键组成的数组。
includes( $ value , ?iterable $ collection ): bool检查$value是否在$collection中。
indexBy(callable $ iteratee , ?iterable $ collection ): iterable创建一个由通过$iteratee运行$collection的每个元素的结果生成的键组成的记录。
map (callable $ iteratee , ?iterable $ collection )通过$iteratee将每个元素运行$collection中的每个元素。
orderBy (array $ iteratees , array $ orders , ?iterable $ collection )像sortBy ,但允许指定排序订单
partition(callable $ predicate , ?iterable $ collection ): array将$collection分为两个组,其中第一个包含元素$predicate返回真相,其中第二个包含元素$predicate返回false。
reduce (callable $ iteratee , $ accumulator , ?iterable $ collection )将$collection降低为一个值,这是通过$iteratee运行每个元素的累积结果
resolve (array $ resolvers , array $ record ): array使用$resolvers将新属性添加到$record 。
sort(array $ comparator , ?iterable $ collection ): array使用$comparator比较( $a <=> $b )功能的$collection
sortBy(array $ comparators , ?iterable $ collection ): array根据$comparators按升级顺序排列$collection 。
sortWith(array $ comparators , ?iterable $ collection ): array根据一系列比较( $a <=> $b )功能进行$collection
values(?iterable $ collection ): iterable返回$collection中值的索引值。
always ( $ value )返回一个始终返回给定值的函数。
applyTo ( $ value , callable $ interceptor )返回$interceptor($value) 。
ary (int $ n , callable $ fn ): callable创建一个调用$fn的函数,最多$n参数,忽略任何其他参数。
ascend (callable $ func , $ a , $ b ): callable从一个返回可以与<=>进行比较的值的函数中,使升级比较器函数从
attempt (callable $ fn )调用$fn ,返回结果或捕获的例外。
compose (callable . . . $ funcs ): callable像pipe一样,但可以调用从右到左的功能。
curry (callable $ f ): callable Idles_ const可以用作占位符。
curryRight (callable $ f ): callable像curry一样,但曾经培养论点。
descend (callable $ func , $ a , $ b ): callable从返回可以与<=>进行比较的值的函数中,使降序比较器函数脱离了函数。
flip (callable $ fn ): callable返回一个新的咖喱功能,前两个参数反向
juxt (array $ funcs ): callable将功能列表应用于值列表。
memoize (callable $ func ): callable创建一个记忆$func结果的函数。 $resolver返回地图高速缓存键,默认情况下,args [0]。
negate (callable $ predicate ): callable创建一个否定$predicate函数结果的函数。
once (callable $ fn ): callable $fn仅被调用一次,在后续调用中返回第一个值。
partial (callable $ fn , array $ partials ): callable创建一个用$partials调用$fn的函数。 Idles_ const可以用作占位符。
partialRight (callable $ fn , array $ partials ): callable像partial但$partials一样。
pipe (callable . . . $ funcs ): callable从左到右功能组成。第一个论点可能具有任何障碍。其余的论点必须是一致的。
tap (callable $ interceptor , $ value )调用$interceptor($value)然后返回原始$value
times (callable $ iteratee , int $ n ): array调用IterateE $n次,返回每个调用结果的数组。
tryCatch (callable $ tryer , callable $ catcher , $ value )调用$tryer ,如果扔了,请调用$catcher
unary (callable $ fn ): callable ary(1, $fn)
allPass (array $ predicates ): callable返回一个函数,该函数是否检查其参数是否通过所有$predicates 。
anyPass (array $ predicates ): callable返回一个函数,该函数检查其参数是否通过$predicates 。
both (callable $ func1 , callable $ func2 ): callable结果功能返回$func1(...$args)如果是虚假的或$func2(...$args) ,否则,短路
cond (array $ pairs ): callable迭代超过$pairs ,并调用第一个谓词的相应功能以返回真相。
defaultTo ( $ default )( $ value )返回$value ?? $default
either (callable $ func1 , callable $ func2 ): callable结果功能返回$func1(...$args)如果是真实的或$func2(...$args) ,否则,短路。
ifElse (callable $ predicate , callable $ onTrue , callable $ onFalse ): callable结果函数返回$onTrue(...$args)如果$predicate(...$args)是真实的或$onFalse(...$args)否则。
not ( $ a ): bool返回!$a
unless (callable $ predicate , callable $ whenFalse , mixed $ value )返回$predicate($value) ? $value : $whenFalse($value)
when (callable $ predicate , callable $ whenTrue , mixed $ value )返回$predicate($value) ? $whenTrue($value) : $value
add (int|float $ a , int|float $ b ): int|float$ a + $ b
dec (int $ number ): int返回$数字-1
divide (int|float $ a , int|float $ b ): int|float$ a / $ b
gt ( $ a , $ b ): bool$ a> $ b
gte ( $ a , $ b ): bool$ a> = $ b
inc (int $ number ): int返回$数字 + 1
lt ( $ a , $ b ): bool$ a <$ b
lte ( $ a , $ b ): bool$ a <= $ b
modulo (int|float $ a , int|float $ b ): int$ a%$ b
multiply (int|float $ a , int|float $ b ): int|float$ a * $ b
round (int $ precision , int|float $ number ): float $number指定的$precision
subtract (int|float $ a , int|float $ b ): int|float$ a -$ b
sum(?iterable $ collection ): int|float概括元素中的元素
sumBy(?callable $ iteratee , ?iterable $ collection ): int|float就像sum一样,但$iteratee在估计中都被调用,以生成要求和的值。
assignDeep (array $ iterables ): array递归合并属性,数字密钥被覆盖。
defaults(?iterable $ record1 , ?iterable $ record2 ): array合并属性从右到左,数字键被覆盖。
evolve(array $ transformations , ?iterable $ record ): array通过递归调用具有$record属性的转换功能来创建新记录。
extend(?iterable $ source1 , ?iterable $ source2 ): array合并属性,数字密钥被覆盖。
has(string|int $ key , ?iterable $ record ): bool检查$record是否有$key
hasPath(string|int|array $ path , ?iterable $ record ): bool检查$path是否存在于$record中
invert(?iterable $ collection ): array用值代替键。重复的键被覆盖。
keys(?iterable $ record ): iterable在$record中返回键的索引。
merge(?iterable $ source1 , ?iterable $ source2 ): array合并属性,数字密钥附加。
mergeDeep (array $ iterables ): array递归合并属性,附加数字密钥。
mergeLeft(?iterable $ left , ?iterable $ right ): array呼叫merge($right, $left)
mergeWith(callable $ customizer , ?iterable $ left , ?iterable $ right ): array像merge $customizer
modifyPath (array|string|int $ path , callable $ updater , ?iterable $ record )通过将$updater功能应用于给定$path的值来创建新记录。
objOf (string $ key , $ value ): array创建一个包含一个键=>值对的array 。
omit(array $ keys , ?iterable $ collection ): iterable pick的对立面。返回记录没有$keys 。
omitBy(callable $ predicate , ?iterable $ record ): iterable pickBy的对立面。返回$record $predicate返回虚假的属性。
path (array|string $ path , ?iterable $ collection )在给定路径上检索值。
paths(array $ paths , ?iterable $ collection ): array键输入,值。保留订单。
pick(array $ keys , ?iterable $ collection ): iterable仅包含$keys返回记录
pickBy(callable $ predicate , ?iterable $ record ): iterable返回记录仅包含键$predicate返回真相。
pluck (string|int $ key , ?iterable $ collection )通过从所提供的阵列中的所有记录中摘下相同的命名属性来返回一个新数组。
prop (string|int $ key , ?iterable $ record )返回指定的属性。
propEq(string|int $ key , $ value , ?iterable $ record ): bool返回$记录[$ key] == $ value
setPath ( $ path , $ value , ?iterable $ record )返回复制$record ,带有$value的$path设置
toPairs(?iterable $ record ): iterable将记录转换为[$key, $value]的数组
where(array $ spec , ?iterable $ record ): bool检查$record是否通过使用$spec $record规格属性来满足规格。
whereAny(array $ spec , ?iterable $ record ): bool检查$record是否通过使用$spec $record规格属性来满足规格。如果至少一个谓词返回true ,则返回true 。
whereEq(array $ spec , ?iterable $ test ): bool检查$test是否满足$spec
escape (string $ s ): string将字符“&”,“”,“”,“','”和“”转换为其相应的HTML实体。
escapeRegExp (string $ regexp ): string逃脱正则表达
split (string $ separator , string $ s ): array通过$separator拆分字符串。
startsWith (string $ target , string $ s ): bool如果字符串以$target开头。
toLower (string $ s ): string将字符串转换为较低的情况
toUpper (string $ s ): string将字符串转换为上情况
words (string $ pattern , string $ string ): array将字符串分成多种单词。
collect(?iterable $ iterable ): array将任何值会收集到array中
eq ( $ a , $ b ): bool $a == $b
equals ( $ a , $ b ): bool $a === $b
F (... $ args ): bool总是返回false
identity ( $ value )返回其收到的第一个参数。
iterate (callable $ f , $ value ): iterable返回$value , $f($value) , $f($f($value))等的生成器。
just ( $ value ): Optional返回带有指定的非零值的可选
nothing(): Optional返回空的可选
now (): int返回秒数的时间戳
just (mixed $ value ): Optional也许/选项monad(容器)可能包含或不包含非零值。有方法:
isPresent(): bool是true如果不是空的isEmpty(): bool true如果是空的get(): mixed - 返回价值,如果空,请抛出异常orElse(mixed $default): mixed - 如果可选的是非空或$default则返回包含的值orElseThrow(Exception $e) - 返回包含的值,如果有的话,否则会引发异常map(callable $f): Optional - 如果存在值,请将$f应用于其,如果结果不为无效,请返回一个可选的描述结果
flatmap(可map flatMap(callable $f): Optional - 如果$f返回可选filter(callable $predicate): Optional - 如果存在一个值并与$predicate匹配,请返回带有该值的可选,否则为空的可选。
size (array|Countable|object|string|callable $ value ): int返回一个可数的函数参数数量,字符串的lenght或对象属性数量的大小
T (... $ args ): bool总是返回true