sockeqwe / mosby

A Model-View-Presenter / Model-View-Intent library for modern Android apps
http://hannesdorfmann.com/mosby/
Apache License 2.0
5.49k stars 841 forks source link

Can ifViewAttached return result of last statement in its scope? #331

Open rishabh876 opened 5 years ago

rishabh876 commented 5 years ago

Hi, this is just a feature request that will make code a bit cleaner and easier to write.

let's say we have

ifViewAttached { 
    val message = it.getStringFromId(R.string.some_id)
    showError(message)
 } 

This will become

val message =  ifViewAttached { it.getStringFromId(R.string.some_id) }
showError(message)

here ifViewAttached returned the value returned by function getStringFromId. This works very similar to let function in Kotlin.

sockeqwe commented 5 years ago

is showError() interacting with the view?

If yes, why would you move showError() outside of the ifViewAttached { ... } block?

rishabh876 commented 5 years ago

This is actually just a simplified logic to show how it can help. I don't use it this way but I prefer writing only view's function inside ifViewAttached and rest outside. Otherwise things look nested for no reason.