
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