Use maxBy { selector } instead of sortedBy { selector }.last()

Proprietary

sortedBy(f).last() does an O(n log n) sort just to read the maximum-by-f. maxBy(f) finds it in a single linear pass.

org.openrewrite.kotlin.performance.UseMaxByForSortedByLast$KtRecipe
mod run . --recipe='org.openrewrite.kotlin.performance.UseMaxByForSortedByLast$KtRecipe'

Install it once from Recipe actions, then run it on every repository under the current directory. New to the Moderne CLI? Set it up.