Skip to content

Instantly share code, notes, and snippets.

@lordcodes
Created March 1, 2020 20:03
Show Gist options
  • Save lordcodes/25f2bf23537b1bc256d3c359fff48091 to your computer and use it in GitHub Desktop.
Save lordcodes/25f2bf23537b1bc256d3c359fff48091 to your computer and use it in GitHub Desktop.
Code for the article: "The power of lazy properties in Kotlin"
class TeamRepository(appSchedulers: AppSchedulers) {
private val viewState by lazy(::createViewStateLiveData)
private fun createViewStateLiveData(): LiveData<ViewState> =
teamRepository.teamMembersStream()
.map(::mapPresentingState)
.onErrorReturn(::mapErrorState)
.startWith(ViewState.Loading)
.subscribeOn(appSchedulers.io)
.observeOn(appSchedulers.main)
.toLiveData()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment