kotlin.reflect.jvm.internal.impl.utils.CollectionUtil.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of kotlin-reflect Show documentation
Show all versions of kotlin-reflect Show documentation
Kotlin Full Reflection Library
/*
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package kotlin.reflect.jvm.internal.impl.utils
inline fun > Iterable<*>.filterIsInstanceAndTo(destination: C, predicate: (R) -> Boolean): C {
for (element in this) {
if (element is R && predicate(element)) {
destination.add(element)
}
}
return destination
}
inline fun > Iterable<*>.filterIsInstanceMapTo(destination: C, transform: (T) -> R): C {
for (element in this) {
if (element is T) {
destination.add(transform(element))
}
}
return destination
}
inline fun Collection<*>.filterIsInstanceMapNotNull(transform: (T) -> R?): Collection {
if (isEmpty()) return emptyList()
return filterIsInstanceMapNotNullTo(SmartList(), transform)
}
inline fun Collection<*>.filterIsInstanceAnd(predicate: (R) -> Boolean): List {
if (isEmpty()) return emptyList()
return filterIsInstanceAndTo(SmartList(), predicate)
}
inline fun > Iterable<*>.filterIsInstanceMapNotNullTo(
destination: C,
transform: (T) -> R?
): C {
for (element in this) {
if (element is T) {
val result = transform(element)
if (result != null) {
destination.add(result)
}
}
}
return destination
}