Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

combineLatestCompat (for java users) and combineLatest(inline/reified) #12

Conversation

adriankremski
Copy link

I was missing these two fellows :). Below some example usage:

private val name = MutableLiveData<String>()
private val email = MutableLiveData<String>()
private val age = MutableLiveData<Int>()
private val money = MutableLiveData<Double>()

val user: LiveData<User> = combineLatest<Any, User>(name, email, age, money) { latestResult ->
    User(name = latestResult[0] as String,
            email = latestResult[1] as? String,
            age = latestResult[2] as Int,
            money = latestResult[3] as Double,
}

data class User(val name: String, val email: String?, val age: Int, val money: Double)

init {
    name.value = "snuffix"
    email.value = null
    age.value = 20
    money.value = 20.0
}

…line/reified). Both of the methods combine the latest values from collection of LiveData objects
@adibfara adibfara added this to the 1.2.2 milestone Feb 7, 2019
@adibfara adibfara removed this from the 1.2.2 milestone Apr 22, 2019
@adibfara
Copy link
Owner

I think having an Any? as the receiver and force-unwrapping it is not a good idea, specially in Kotlin world. (Similar issue in RxKotlin here)

@adibfara adibfara closed this Jun 24, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants