# Kotlin 2.4.20 Collection Checks and Experimental Context-Sensitive Resolution

DevFeed: [Kotlin 2.4.20 Collection Checks and Experimental Context-Sensitive Resolution](<https://devfeed.tech/articles/features-you-waited-for-so-long-in-kotlin-22944.md>)

Original publisher: [Read original article](<https://proandroiddev.com/features-you-waited-for-so-long-in-kotlin-6c822e9e344a?source=rss----c72404660798---4>)

Author: Andrii Dubovyk

Published: 2026-09-14T06:32:51Z

Content type: tutorial

Language: en

Sources: [ProAndroidDev - Medium](<https://devfeed.tech/sources/proandroiddev-medium.md>)

Topics: [Kotlin](<https://devfeed.tech/topics/kotlin.md>), [Compiler](<https://devfeed.tech/topics/compiler.md>), [Code](<https://devfeed.tech/topics/code.md>)

Tags: [android](<https://devfeed.tech/tags/android.md>), [android-development](<https://devfeed.tech/tags/android-development.md>), [collections](<https://devfeed.tech/tags/collections.md>), [compiler](<https://devfeed.tech/tags/compiler.md>), [experimental](<https://devfeed.tech/tags/experimental.md>), [features](<https://devfeed.tech/tags/features.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [list](<https://devfeed.tech/tags/list.md>), [mobile-app-development](<https://devfeed.tech/tags/mobile-app-development.md>), [syntax](<https://devfeed.tech/tags/syntax.md>), [technology](<https://devfeed.tech/tags/technology.md>)

## AI overview

The article explains two Kotlin features: allDistinctBy and allEqualBy in Kotlin 2.4.20 for checking collection values, and experimental context-sensitive resolution introduced in Kotlin 2.2 to reduce repetition when the expected type is known.

## Source excerpt

Kotlin 2.4.20 gives your collections opinions, and 2.2's compiler finally learns to read the room Some Kotlin features get a lot of attention when they arrive. Others are much less noticeable, but still make everyday code a little easier to write. Two examples of the latter are allDistinctBy/ allEqualBy in Kotlin 2.4.20 and context-sensitive resolution, which was introduced experimentally in Kotlin 2.2. allDistinctBy/ allEqualBy: A Simpler Way to Check Collections For years, checking whether all values in a collection were unique often looked something like this: val users = listOf( User(name = "A", age = 20), User(name = "B", age = 25), User(name = "C", age = 30) ) users.map { it.age }.distinct().size == users.size // true It works, but it creates another list, removes duplicates, counts the result, and then compares the sizes just to get a Boolean answer. Kotlin 2.4.20 adds a more direct way to express the same check: users.allDistinctBy { it.age } // true users.allEqualBy { it.age } // false allDistinctBy returns false as soon as it finds a duplicate, so it doesn't need to process the entire collection or create a separate Set. allEqualBy does the opposite: it checks whether all elements produce the same value when passed through the selector. Both functions work with Iterable, Sequence, and arrays. They use structural equality. For floating-point values, they follow Double.equals semantics, so NaN is considered equal to NaN, while -0.0 is different from 0.0. They're still @ExperimentalStdlibApi, so you'll need to opt in before using them in production code. The underlying allDistinct() and allEqual() requests have also been around in YouTrack for quite a while, which makes their appearance in the standard library feel long overdue. Context-Sensitive Resolution: Less Repetition in when The second feature is more about syntax. When the compiler already knows the type you're working with, you can sometimes leave out the type qualifier. Before: enum class Problem {