none

컬렉션이 비어있는지 확인

public fun <T> Iterable<T>.none(): Boolean {
    for (element in this) return false
    return true
}


val list = listOf(1, 2, 3, 4, 5)
println(list.none())  // false

public inline fun <T> Iterable<T>.none(predicate: (T) -> Boolean): Boolean {
    for (element in this) if (predicate(element)) return false
    return true
}


val list = listOf(1, 2, 3, 4, 5)
println(list.none{ it > 0 })  // false
println(list.none{ it < 0 })  // true
println(list.none{ it > 3 })  // false

Last updated