aboutsummaryrefslogtreecommitdiff
path: root/core/src/main/kotlin/utilities/Collections.kt
blob: b18752f777e96a7af48bffa04fb5f2f795bfdc2b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
package org.jetbrains.dokka.utilities

import org.jetbrains.dokka.InternalDokkaApi

/**
 * This utility method was previously imported from `org.jetbrains.kotlin.utils.addToStdlib`,
 * and there were a lot of usages. Since no replacement exists in stdlib, it was implemented
 * locally for convenience.
 */
@InternalDokkaApi
inline fun <reified T : Any> Iterable<*>.firstIsInstanceOrNull(): T? {
    for (element in this) if (element is T) return element
    return null
}

/**
 * This utility method was previously imported from `org.jetbrains.kotlin.utils.addToStdlib`,
 * and there were a lot of usages. Since no replacement exists in stdlib, it was implemented
 * locally for convenience.
 */
@InternalDokkaApi
inline fun <reified T : Any> Sequence<*>.firstIsInstanceOrNull(): T? {
    for (element in this) if (element is T) return element
    return null
}