Find firstOrNull { } ?: error(...) patterns

Proprietary

firstOrNull { p }.let { it ?: error("missing") } (or the ?: error form) is a manual single { p } — single throws when there's no match or more than one, which is usually the intended precondition.

org.openrewrite.kotlin.idiom.FindFirstOrNullElvisError$KtRecipe
mod run . --recipe='org.openrewrite.kotlin.idiom.FindFirstOrNullElvisError$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.