0

Is there any way I can transform an object of type LiveData<List<X>> to an object of type LiveData<PagedList<X>>?

Merov
  • 1,028
  • 1
  • 14
  • 29
Lilian Sorlanski
  • 405
  • 1
  • 3
  • 15

1 Answers1

0

As much as i understood you can do it in the followed way:

    class FirstType
    class SecondType

    val initType: LiveData<FirstType> = MutableLiveData<FirstType>()
    val resultType : LiveData<SecondType> = Transformations.map(initType, ::convertTypes)

    fun convertTypes(firstType: FirstType) : SecondType = SecondType()

upd:
What about converting List<T> to PagedList<T> try to look at:
How to convert a List<Object> to PagedList<Object> and vice-versa?

Merov
  • 1,028
  • 1
  • 14
  • 29
  • It is not about changing the type from `FirstType` to `SecondType`. The type is the same `X`. It's about transforming a `LiveData>` in `LiveData>`, see `List` into `PagedList`. Is there any way I can do that? – Lilian Sorlanski Jul 09 '19 at 10:41
  • Thanks for the update but `snapshot()` transforms a `PagedList` to a `List `and I need the vice-versa. Is it even possible? – Lilian Sorlanski Jul 09 '19 at 10:52
  • In the answer from the link, after `snapshot()` explanation, starting from `Now as for the other way around...` is it not what you need? – Merov Jul 09 '19 at 10:59
  • Let me check again and I get back to you. – Lilian Sorlanski Jul 09 '19 at 11:05