Find if (predicate(x)) x else null patterns
Proprietaryif (predicate(x)) x else null is x.takeIf { predicate(it) } written long-hand. The takeIf form keeps the value as the focal point and composes with ?.let { } / elvis (x.takeIf { … } ?: default).
org. openrewrite. kotlin. functional. FindUseTakeIfForFilter$KtRecipemod run . --recipe= 'org. openrewrite. kotlin. functional. FindUseTakeIfForFilter$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.