android-ktx icon indicating copy to clipboard operation
android-ktx copied to clipboard

For consistency, withXXX methods should return the last value of the passed lambda

Open LouisCAD opened this issue 7 years ago • 2 comments

with from Kotlin stdlib returns value of its last expression, if any, and in other places of the Kotlin world, withXXX methods do the same to follow this convention, yet in androidx they return Unit as seen there: https://android.github.io/android-ktx/core-ktx/androidx.graphics/android.graphics.-canvas/index.html

This should be fixed for the sake of consistency.

LouisCAD avatar Mar 13 '18 09:03 LouisCAD

I'd be open to returning the Canvas. I don't see much reason to return from the lambda though.

JakeWharton avatar Mar 13 '18 13:03 JakeWharton

If the methods don't return the last expression, they shouldn't be named withXXX IMHO.

doWithXXX or applyWithXXX would be less confusing in regards to the naming convention. The do variant may return Unit and the apply variant, the Canvas, following what apply from Kotlin stdlib does.

LouisCAD avatar Mar 13 '18 13:03 LouisCAD