Skip to content

Commit 0b5bb7f

Browse files
committed
Added Sequence.findLastIndex, Sequence.lastIndex functions in UtilsFactory
1 parent 160856e commit 0b5bb7f

File tree

1 file changed

+13
-0
lines changed
  • yukihookapi/src/main/java/com/highcapable/yukihookapi/hook/utils

1 file changed

+13
-0
lines changed

yukihookapi/src/main/java/com/highcapable/yukihookapi/hook/utils/UtilsFactory.kt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,19 @@ internal inline fun <reified T> Array<out T>.value() = if (isNotEmpty()) {
7373
"[${value.trim().let { it.substring(0, it.lastIndex) }}]"
7474
} else "[]"
7575

76+
/**
77+
* 通过 [conditions] 查找符合条件的最后一个元素的下标
78+
* @return [Int] 没有找到符合条件的下标将返回 -1
79+
*/
80+
internal inline fun <reified T> Sequence<T>.findLastIndex(conditions: (T) -> Boolean) =
81+
withIndex().findLast { conditions(it.value) }?.index ?: -1
82+
83+
/**
84+
* 返回最后一个元素的下标
85+
* @return [Int] 如果 [Sequence] 为空将返回 -1
86+
*/
87+
internal inline fun <reified T> Sequence<T>.lastIndex() = foldIndexed(-1) { index, _, _ -> index }.takeIf { it >= 0 } ?: -1
88+
7689
/**
7790
* 满足条件判断方法体 - 对 [kotlin.takeIf] 进行封装
7891
* @param other 需要满足不为空的对象 - 仅用于判断是否为 null

0 commit comments

Comments
 (0)