Skip to content

Instantly share code, notes, and snippets.

@tobioyelekan
Last active July 3, 2020 14:47
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tobioyelekan/0e689d1f0f89fcfc7be1b306114522c4 to your computer and use it in GitHub Desktop.
Save tobioyelekan/0e689d1f0f89fcfc7be1b306114522c4 to your computer and use it in GitHub Desktop.
typical user view model
private val userId = MutableLiveData<String>()
val userDetails = userId.switchMap {
userRepo.getUser(it)
}
val userFullName = userDetails.map {
getFullName(it.firstName, it.lastName)
}
fun setUserId(userId: String) {
this.userId.value = userId
}
fun getFullName(firstName: String, lastName: String) = "$firstName $lastName"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment