https://kotlinlang.org logo
#getting-started
Title
# getting-started
m

Mark

07/07/2020, 5:52 AM
I have an extension function declared within a
Fragment
subclass:
Copy code
inline fun <T> Flow<T>.collectInViewScope(crossinline action: suspend (value: T) -> Unit) {
    viewLifecycleOwner.lifecycleScope.launch { 
        collect(action)
    }
}
But is there a way to declare this outside of the class (so it can be used from any
Fragment
subclass, without having to pass in the
Fragment
instance as an arg? A kind of extension function with added context of the call site. One could imagine
inline <http://Fragment.fun|Fragment.fun> <T> Flow<T>.collectInViewScope(…)
🚫 2
m

Milan Hruban

07/07/2020, 6:17 AM
No, i'ts not possible to have multiple receivers. https://github.com/Kotlin/KEEP/pull/176
👍 1
2 Views