mapQuery

fun <D : IviDataSource<E, Q>, E : Any, Q : Any> Flow<D>.mapQuery(query: Q): Flow<IviPagingSource<E>>

Transforms this IviDataSource to an IviPagingSource for the given query.

A new IviPagingSource is emitted when the IviPagingSource is invalidated or when the IviDataSource emits a new value.

Common transformations exist to transform returned IviPagingSource to load data from the IviPagingSource. See for instance toList and first. For custom transformations use mapQuery which takes a query and a transaction lambda.

Example usages:

val dataSourceFlow: Flow<IviDataSource<Contact, ContactDataSourceQuery>> = ...
val query: ContactDataSourceQuery = ...
val firstContactFlow: Flow<Contact> = dataSourceFlow.mapQuery(query).first()

The same mapQuery extension exists for an IviDataSource. For mapping a query to a PagingData use createPagingDataFlow in module platform_framework_api_ipc_iviserviceandroidpaging instead.


fun <D : IviDataSource<E, Q>, E : Any, Q : Any, R> Flow<D>.mapQuery(query: Q, transformation: suspend (PageProvider<E>) -> R): Flow<R>

Transforms this IviDataSource to a R for the given query and given transformation lambda.

The transformation lambda is called each time after an IviPagingSource is created. A new IviPagingSource is created after the IviDataSource emits a new value or after the previous created IviPagingSource is invalidated.

The transformation lambda is given a PageProvider. This provider can be used to load one or more pages from the created IviPagingSource to transform the page data into an instance of type R.

The transformation lambda must be exception transparent to facilitate the creation of a new IviPagingSource when the IviPagingSource is invalidated while loading pages.

Example usage:

val dataSourceFlow: Flow<IviDataSource<Contact, ContactDataSourceQuery>> = ...
val query: ContactDataSourceQuery = ...
val contactsFlow: Flow<List<Contact>> = dataSourceFlow.mapQuery(query) { pageProvider ->
val page1 = pageProvider(...)
val page2 = pageProvider(...)
page1.data + page2.data
}

Common transformations exist. See for instance toList and first. The same mapQuery extension exists for an IviDataSource.

For mapping a query to a PagingData use createPagingDataFlow in module platform_framework_api_ipc_iviserviceandroidpaging instead. In this case the transformation can be applied with the PagingDatamap extensions.


fun <D : IviDataSource<E, Q>, E : Any, Q : Any> LiveData<D>.mapQuery(query: Q, timeout: Duration = Duration.ZERO): LiveData<IviPagingSource<E>>

Transforms this IviDataSource to a IviPagingSource for a given query. If the returned LiveData becomes inactive while values are still being emited, the underlying coroutine will be cancelled after the timeout, unless the LiveData becomes active again before that timeout. By default timeout is Duration.ZERO, which means that once the returned LiveData becomes inactive it is not usable anymore.

A new IviPagingSource is observed when the IviPagingSource is invalidated or when the IviDataSource changes.

Common transformations exist to transform returned IviPagingSource to load data from the IviPagingSource. See for instance toList and first. For custom transformations use mapQuery which takes a query and a transaction lambda.

Example usages:

val dataSourceLiveData: LiveData<IviDataSource<Contact, ContactDataSourceQuery>> = ...
val query: ContactDataSourceQuery = ...
val firstContactLiveData: LiveData<Contact> = dataSourceLiveData.mapQuery(query).first()

The same mapQuery extension exists for an IviPagingSource. For mapping a query to a PagingData use mapPagingData in module platform_framework_api_ipc_iviserviceandroidpaging instead.


fun <D : IviDataSource<E, Q>, E : Any, Q : Any, R> LiveData<D>.mapQuery(    query: Q,     timeout: Duration = Duration.ZERO,     transformation: suspend (PageProvider<E>) -> R): LiveData<R>

Transforms this IviDataSource to a LiveData of type R for a given query and a given transformation. If the returned LiveData becomes inactive while values are still being emited, the underlying coroutine will be cancelled after the timeout, unless the LiveData becomes active again before that timeout. By default timeout is Duration.ZERO, which means that once the returned LiveData becomes inactive it is not usable anymore.

The transformation lambda is called each time after an IviPagingSource is created. A new IviPagingSource is created after the IviDataSource changes value or after the previous created IviPagingSource is invalidated.

The transformation lambda is given a PageProvider. This provider can be used to load one or more pages from the created IviPagingSource to transform the page data into an instance of type R.

The transformation lambda must be exception transparent to facilitate the creation of a new IviPagingSource when the IviPagingSource is invalidated while loading pages.

Example usage:

val dataSourceLiveData: LiveData<IviDataSource<Contact, ContactDataSourceQuery>> = ...
val query: ContactDataSourceQuery = ...
val contactsLiveData: LiveData<List<Contact>> =
dataSourceLiveData.mapQuery(query) { pageProvider ->
val page1 = pageProvider(...)
val page2 = pageProvider(...)
page1.data + page2.data
}

Common transformations exist. See for instance toList and first. The same mapQuery extension exists for an IviPagingSource. For mapping a query to a PagingData use mapPagingData in module platform_framework_api_ipc_iviserviceandroidpaging instead. In this case the transformation can be applied with the PagingDatamap extensions.