Skip to content

Instantly share code, notes, and snippets.

@AkshayChordiya
Last active August 21, 2017 12:52
Show Gist options
  • Save AkshayChordiya/996478faac134a1457efc2003d82f75f to your computer and use it in GitHub Desktop.
Save AkshayChordiya/996478faac134a1457efc2003d82f75f to your computer and use it in GitHub Desktop.
UserViewModel with LiveData map transformation
class UserViewModel() : ViewModel() {
/**
* The user
*/
private var user: LiveData<User>
/**
* Full name of the user
*/
private var userFullName: LiveData<String>
init {
// Update the full name when user is changed
userFullName = Transformations.map(user) { user -> "$user.firstName $user.lastName" }
}
/**
* Get the data
*/
fun getUser() = user
}
@Androbin
Copy link

Androbin commented Aug 21, 2017

Could it be, you wanted a setter for user and a getter for userFullName here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment