#每天一个知识点# kotlin 集合快速筛选方法
it?.filterList {
this.isSelect
}

inline fun <T> Iterable<T>.filterList(predicate: T.() -> Boolean): List<T> {
var result: List<T> = emptyList()
for (i in this) {
if (predicate(i)) {
if (result.isEmpty()) result = mutableListOf()
(result as MutableList<T>).add(i)
}
}
return result
}
展开
评论