> For the complete documentation index, see [llms.txt](https://gold.gitbook.io/kotlin/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://gold.gitbook.io/kotlin/collections/aggregate-operations/minby.md).

# minBy

```kotlin
public inline fun <T, R : Comparable<R>> Iterable<T>.minBy(selector: (T) -> R): T? {
    val iterator = iterator()
    if (!iterator.hasNext()) return null
    var minElem = iterator.next()
    var minValue = selector(minElem)
    while (iterator.hasNext()) {
        val e = iterator.next()
        val v = selector(e)
        if (minValue > v) {
            minElem = e
            minValue = v
        }
    }
    return minElem
}


val list = listOf(Person("a", 10), Person("b", 20), Person("c", 30))
println(list.minBy{ it.age })  // Person(name=a, age=10)
```
