Search code examples
androidarrayskotlinarraylistmutablelivedata

How do I append one MutableLiveData List to Another in Kotlin


I have two MutableLiveData Lists like so

  val products = MutableLiveData<List<Product>>()
  val moreProducts = MutableLiveData<List<Product>>()

Please how do I append 'moreProducts' to 'products' in Kotlin


Solution

  • You can do it like this

    products.value = prducts.value.orEmpty() + moreProducts.value.orEmpty()