Skip to content

Instantly share code, notes, and snippets.

@Eduardo-Nunes
Last active June 30, 2020 17:24
Show Gist options
  • Save Eduardo-Nunes/78de57611617cd65eb9257b61ee8a1b3 to your computer and use it in GitHub Desktop.
Save Eduardo-Nunes/78de57611617cd65eb9257b61ee8a1b3 to your computer and use it in GitHub Desktop.
Lifecycle observer lazy instance with Kotlin
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.Observer
infix fun <T : Any?> LifecycleOwner.lazyObserver(func: (T) -> Unit): Lazy<Observer<T>> {
return lazyOf(Observer(func))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment