Has the introduction of something like: ```fun &lt...
# stdlib
a
Has the introduction of something like:
Copy code
fun <T> Boolean.map(valueTrue: T, valueFalse: T): T = if(this) valueTrue else valueFalse
in the stdlib been already asked/taken into consideration?
s
I imagine you have a use case in mind? I’m not sure why this would be preferable to a standard if/else
👍🏼 1
👆 1
a
Example (something I’ve just done):
Copy code
fun setLoading(loading: Boolean) = loading.map(View.VISIBLE, View.INVISIBLE)
I mean, pardon, the full implementation is:
Copy code
override fun showLoading(loading: Boolean) {
    progressBar.visibility = loading.map(View.VISIBLE, View.INVISIBLE)
}
s
Copy code
progressBar.visibility = if (loading) View.VISIBLE else View.INVISIBLE
much clearer than
.map(??, ??)
1
s
I can definitely see the use case for it, although I do think the if/else is more readable
j
if/else is also lazy
if (loading) computeSomething() else computeOtherThing()
☝️ 4