Skip to content

Conversation

Komdosh
Copy link

@Komdosh Komdosh commented Oct 18, 2025

There is a find and filterIs methods for iterables, but there is no method for finding one specific element in iterable.

For example:

val services = listOf<CommonInterface>(specificInterfaceA, specificInterfaceB, specificInterfaceC)

val specificService = services.findIs<SpecificInterfaceB>()

it is easy to implement, but it is still not in stdlib.

public inline fun <reified R> Iterable<*>.findIs(): R? {
    return find { element -> element is R } as R?
}

Forgotten for 11 years actually: KT-6300

@Komdosh Komdosh changed the title KT-6300: Stdlib: add findIs and firstIs method [KT-6300]: Stdlib: add findIs and firstIs method Oct 18, 2025
@Komdosh Komdosh requested a review from a team as a code owner October 20, 2025 15:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants