# PagingData

Artifact: [androidx.paging:paging-common](https://developer.android.com/jetpack/androidx/releases/paging) [View Source](https://cs.android.com/search?q=file:androidx/paging/PagingData.kt+class:androidx.paging.PagingData) Added in [3.0.0](https://developer.android.com/jetpack/androidx/releases/paging#3.0.0)

*** ** * ** ***

Common/AllAndroid/JVMNative/C/iOSJavaScript
- Cmn

  ```
  class PagingData<T : Any>
  ```

*** ** * ** ***

Container for Paged data from a single generation of loads.

Each refresh of data (generally either pushed by local storage, or pulled from the network) will have a separate corresponding `https://developer.android.com/reference/kotlin/androidx/paging/PagingData`.

## Summary

| ### Public companion functions |
|---|---|---|
| `https://developer.android.com/reference/kotlin/androidx/paging/PagingData<T>` | `<T : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html> https://developer.android.com/reference/kotlin/androidx/paging/PagingData#empty()()` Create a `https://developer.android.com/reference/kotlin/androidx/paging/PagingData` that immediately displays an empty list of items when submitted to a presenter. | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/paging/PagingData<T>` | `<T : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html> https://developer.android.com/reference/kotlin/androidx/paging/PagingData#empty(androidx.paging.LoadStates,androidx.paging.LoadStates)(sourceLoadStates: https://developer.android.com/reference/kotlin/androidx/paging/LoadStates, mediatorLoadStates: https://developer.android.com/reference/kotlin/androidx/paging/LoadStates?)` Create a `https://developer.android.com/reference/kotlin/androidx/paging/PagingData` that immediately displays an empty list of items when submitted to a presenter. | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/paging/PagingData<T>` | `<T : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html> https://developer.android.com/reference/kotlin/androidx/paging/PagingData#from(kotlin.collections.List,kotlin.Int,kotlin.Int)(data: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<T>, placeholdersBefore: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, placeholdersAfter: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Create a `https://developer.android.com/reference/kotlin/androidx/paging/PagingData` that immediately displays a static list of items when submitted to a presenter. | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/paging/PagingData<T>` | `<T : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html> https://developer.android.com/reference/kotlin/androidx/paging/PagingData#from(kotlin.collections.List,androidx.paging.LoadStates,androidx.paging.LoadStates,kotlin.Int,kotlin.Int)( data: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<T>, sourceLoadStates: https://developer.android.com/reference/kotlin/androidx/paging/LoadStates, mediatorLoadStates: https://developer.android.com/reference/kotlin/androidx/paging/LoadStates?, placeholdersBefore: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, placeholdersAfter: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html )` Create a `https://developer.android.com/reference/kotlin/androidx/paging/PagingData` that immediately displays a static list of items when submitted to a presenter. | Cmn |

| ### Extension functions |
|---|---|---|
| `https://developer.android.com/reference/kotlin/androidx/paging/PagingData<T>` | `<T : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html> https://developer.android.com/reference/kotlin/androidx/paging/PagingData<T>.https://developer.android.com/reference/kotlin/androidx/paging/PagingData#(androidx.paging.PagingData).filterAsync(com.google.common.util.concurrent.AsyncFunction,java.util.concurrent.Executor)( predicate: https://guava.dev/releases/snapshot-android/api/docs/com/google/common/util/concurrent/AsyncFunction.html<T, https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html>, executor: https://developer.android.com/reference/java/util/concurrent/Executor.html )` Returns a `https://developer.android.com/reference/kotlin/androidx/paging/PagingData` containing only elements matching the given `https://developer.android.com/reference/kotlin/androidx/paging/package-summary#(androidx.paging.PagingData).filterAsync(com.google.common.util.concurrent.AsyncFunction,java.util.concurrent.Executor)`. | android |
| `https://developer.android.com/reference/kotlin/androidx/paging/PagingData<R>` | `<T : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html, R : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html> https://developer.android.com/reference/kotlin/androidx/paging/PagingData<T>.https://developer.android.com/reference/kotlin/androidx/paging/PagingData#(androidx.paging.PagingData).flatMapAsync(com.google.common.util.concurrent.AsyncFunction,java.util.concurrent.Executor)( transform: https://guava.dev/releases/snapshot-android/api/docs/com/google/common/util/concurrent/AsyncFunction.html<T, https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-iterable/index.html<R>>, executor: https://developer.android.com/reference/java/util/concurrent/Executor.html )` Returns a `https://developer.android.com/reference/kotlin/androidx/paging/PagingData` of all elements returned from applying the given `https://developer.android.com/reference/kotlin/androidx/paging/package-summary#(androidx.paging.PagingData).flatMapAsync(com.google.common.util.concurrent.AsyncFunction,java.util.concurrent.Executor)` to each element, as it is loaded. | android |
| `https://developer.android.com/reference/kotlin/androidx/paging/PagingData<R>` | `<T : R, R : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html> https://developer.android.com/reference/kotlin/androidx/paging/PagingData<T>.https://developer.android.com/reference/kotlin/androidx/paging/PagingData#(androidx.paging.PagingData).insertSeparatorsAsync(com.google.common.util.concurrent.AsyncFunction,java.util.concurrent.Executor)( generator: https://guava.dev/releases/snapshot-android/api/docs/com/google/common/util/concurrent/AsyncFunction.html<https://developer.android.com/reference/kotlin/androidx/paging/AdjacentItems<T>, R?>, executor: https://developer.android.com/reference/java/util/concurrent/Executor.html )` Returns a `https://developer.android.com/reference/kotlin/androidx/paging/PagingData` containing each original element, with an optional separator generated by `https://developer.android.com/reference/kotlin/androidx/paging/package-summary#(androidx.paging.PagingData).insertSeparatorsAsync(com.google.common.util.concurrent.AsyncFunction,java.util.concurrent.Executor)`, given the elements before and after (or null, in boundary conditions). | android |
| `https://developer.android.com/reference/kotlin/androidx/paging/PagingData<R>` | `<T : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html, R : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html> https://developer.android.com/reference/kotlin/androidx/paging/PagingData<T>.https://developer.android.com/reference/kotlin/androidx/paging/PagingData#(androidx.paging.PagingData).mapAsync(com.google.common.util.concurrent.AsyncFunction,java.util.concurrent.Executor)( transform: https://guava.dev/releases/snapshot-android/api/docs/com/google/common/util/concurrent/AsyncFunction.html<T, R>, executor: https://developer.android.com/reference/java/util/concurrent/Executor.html )` Returns a `https://developer.android.com/reference/kotlin/androidx/paging/PagingData` containing the result of applying the given `https://developer.android.com/reference/kotlin/androidx/paging/package-summary#(androidx.paging.PagingData).mapAsync(com.google.common.util.concurrent.AsyncFunction,java.util.concurrent.Executor)` to each element, as it is loaded. | android |
| `https://developer.android.com/reference/kotlin/androidx/paging/PagingData<T>` | `<T : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html> https://developer.android.com/reference/kotlin/androidx/paging/PagingData<T>.https://developer.android.com/reference/kotlin/androidx/paging/PagingData#(androidx.paging.PagingData).filter(kotlin.coroutines.SuspendFunction1)(predicate: suspend (T) -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)` Returns a `https://developer.android.com/reference/kotlin/androidx/paging/PagingData` containing only elements matching the given `https://developer.android.com/reference/kotlin/androidx/paging/package-summary#(androidx.paging.PagingData).filter(kotlin.coroutines.SuspendFunction1)` | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/paging/PagingData<T>` | `<T : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html> https://developer.android.com/reference/kotlin/androidx/paging/PagingData<T>.https://developer.android.com/reference/kotlin/androidx/paging/PagingData#(androidx.paging.PagingData).filter(java.util.concurrent.Executor,kotlin.Function1)(executor: https://developer.android.com/reference/java/util/concurrent/Executor.html, predicate: (T) -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)` Returns a `https://developer.android.com/reference/kotlin/androidx/paging/PagingData` containing only elements matching the given `https://developer.android.com/reference/kotlin/androidx/paging/package-summary#(androidx.paging.PagingData).filter(java.util.concurrent.Executor,kotlin.Function1)`. | android |
| `https://developer.android.com/reference/kotlin/androidx/paging/PagingData<R>` | `<T : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html, R : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html> https://developer.android.com/reference/kotlin/androidx/paging/PagingData<T>.https://developer.android.com/reference/kotlin/androidx/paging/PagingData#(androidx.paging.PagingData).flatMap(kotlin.coroutines.SuspendFunction1)(transform: suspend (T) -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-iterable/index.html<R>)` Returns a `https://developer.android.com/reference/kotlin/androidx/paging/PagingData` of all elements returned from applying the given `https://developer.android.com/reference/kotlin/androidx/paging/package-summary#(androidx.paging.PagingData).flatMap(kotlin.coroutines.SuspendFunction1)` to each element, as it is loaded. | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/paging/PagingData<R>` | `<T : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html, R : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html> https://developer.android.com/reference/kotlin/androidx/paging/PagingData<T>.https://developer.android.com/reference/kotlin/androidx/paging/PagingData#(androidx.paging.PagingData).flatMap(java.util.concurrent.Executor,kotlin.Function1)( executor: https://developer.android.com/reference/java/util/concurrent/Executor.html, transform: (T) -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-iterable/index.html<R> )` Returns a `https://developer.android.com/reference/kotlin/androidx/paging/PagingData` of all elements returned from applying the given `https://developer.android.com/reference/kotlin/androidx/paging/package-summary#(androidx.paging.PagingData).flatMap(java.util.concurrent.Executor,kotlin.Function1)` to each element, as it is loaded. | android |
| `https://developer.android.com/reference/kotlin/androidx/paging/PagingData<T>` | `<T : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html> https://developer.android.com/reference/kotlin/androidx/paging/PagingData<T>.https://developer.android.com/reference/kotlin/androidx/paging/PagingData#(androidx.paging.PagingData).insertFooterItem(androidx.paging.TerminalSeparatorType,kotlin.Any)( terminalSeparatorType: https://developer.android.com/reference/kotlin/androidx/paging/TerminalSeparatorType, item: T )` Returns a `https://developer.android.com/reference/kotlin/androidx/paging/PagingData` containing each original element, with the passed footer `https://developer.android.com/reference/kotlin/androidx/paging/package-summary#(androidx.paging.PagingData).insertFooterItem(androidx.paging.TerminalSeparatorType,kotlin.Any)` added to the end of the list. | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/paging/PagingData<T>` | `<T : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html> https://developer.android.com/reference/kotlin/androidx/paging/PagingData<T>.https://developer.android.com/reference/kotlin/androidx/paging/PagingData#(androidx.paging.PagingData).insertHeaderItem(androidx.paging.TerminalSeparatorType,kotlin.Any)( terminalSeparatorType: https://developer.android.com/reference/kotlin/androidx/paging/TerminalSeparatorType, item: T )` Returns a `https://developer.android.com/reference/kotlin/androidx/paging/PagingData` containing each original element, with the passed header `https://developer.android.com/reference/kotlin/androidx/paging/package-summary#(androidx.paging.PagingData).insertHeaderItem(androidx.paging.TerminalSeparatorType,kotlin.Any)` added to the start of the list. | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/paging/PagingData<R>` | `<T : R, R : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html> https://developer.android.com/reference/kotlin/androidx/paging/PagingData<T>.https://developer.android.com/reference/kotlin/androidx/paging/PagingData#(androidx.paging.PagingData).insertSeparators(androidx.paging.TerminalSeparatorType,kotlin.coroutines.SuspendFunction2)( terminalSeparatorType: https://developer.android.com/reference/kotlin/androidx/paging/TerminalSeparatorType, generator: suspend (T?, T?) -> R? )` Returns a `https://developer.android.com/reference/kotlin/androidx/paging/PagingData` containing each original element, with an optional separator generated by `https://developer.android.com/reference/kotlin/androidx/paging/package-summary#(androidx.paging.PagingData).insertSeparators(androidx.paging.TerminalSeparatorType,kotlin.coroutines.SuspendFunction2)`, given the elements before and after (or null, in boundary conditions). | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/paging/PagingData<R>` | `<R : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html, T : R> https://developer.android.com/reference/kotlin/androidx/paging/PagingData<T>.https://developer.android.com/reference/kotlin/androidx/paging/PagingData#(androidx.paging.PagingData).insertSeparators(androidx.paging.TerminalSeparatorType,java.util.concurrent.Executor,kotlin.Function2)( terminalSeparatorType: https://developer.android.com/reference/kotlin/androidx/paging/TerminalSeparatorType, executor: https://developer.android.com/reference/java/util/concurrent/Executor.html, generator: (T?, T?) -> R? )` Returns a `https://developer.android.com/reference/kotlin/androidx/paging/PagingData` containing each original element, with an optional separator generated by `https://developer.android.com/reference/kotlin/androidx/paging/package-summary#(androidx.paging.PagingData).insertSeparators(androidx.paging.TerminalSeparatorType,java.util.concurrent.Executor,kotlin.Function2)`, given the elements before and after (or null, in boundary conditions). | android |
| `https://developer.android.com/reference/kotlin/androidx/paging/PagingData<R>` | `<T : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html, R : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html> https://developer.android.com/reference/kotlin/androidx/paging/PagingData<T>.https://developer.android.com/reference/kotlin/androidx/paging/PagingData#(androidx.paging.PagingData).map(kotlin.coroutines.SuspendFunction1)(transform: suspend (T) -> R)` Returns a `https://developer.android.com/reference/kotlin/androidx/paging/PagingData` containing the result of applying the given `https://developer.android.com/reference/kotlin/androidx/paging/package-summary#(androidx.paging.PagingData).map(kotlin.coroutines.SuspendFunction1)` to each element, as it is loaded. | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/paging/PagingData<R>` | `<T : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html, R : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html> https://developer.android.com/reference/kotlin/androidx/paging/PagingData<T>.https://developer.android.com/reference/kotlin/androidx/paging/PagingData#(androidx.paging.PagingData).map(java.util.concurrent.Executor,kotlin.Function1)(executor: https://developer.android.com/reference/java/util/concurrent/Executor.html, transform: (T) -> R)` Returns a `https://developer.android.com/reference/kotlin/androidx/paging/PagingData` containing the result of applying the given `https://developer.android.com/reference/kotlin/androidx/paging/package-summary#(androidx.paging.PagingData).map(java.util.concurrent.Executor,kotlin.Function1)` to each element, as it is loaded. | android |
| `https://developer.android.com/reference/kotlin/androidx/paging/PagingData<T>` | `<T : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html> https://developer.android.com/reference/kotlin/androidx/paging/PagingData<T>.https://developer.android.com/reference/kotlin/androidx/paging/PagingData#(androidx.paging.PagingData).filterAsync(kotlin.Function1)(predicate: (T) -> https://reactivex.io/RxJava/2.x/javadoc/io/reactivex/Single.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html>)` Returns a `https://developer.android.com/reference/kotlin/androidx/paging/PagingData` containing only elements matching the given `https://developer.android.com/reference/kotlin/androidx/paging/rxjava2/package-summary#(androidx.paging.PagingData).filterAsync(kotlin.Function1)`. | android |
| `https://developer.android.com/reference/kotlin/androidx/paging/PagingData<T>` | `<T : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html> https://developer.android.com/reference/kotlin/androidx/paging/PagingData<T>.https://developer.android.com/reference/kotlin/androidx/paging/PagingData#(androidx.paging.PagingData).filterAsync(kotlin.Function1)(predicate: (T) -> http://reactivex.io/RxJava/3.x/javadoc/io/reactivex/rxjava3/core/Single.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html>)` Returns a `https://developer.android.com/reference/kotlin/androidx/paging/PagingData` containing only elements matching the given `https://developer.android.com/reference/kotlin/androidx/paging/rxjava3/package-summary#(androidx.paging.PagingData).filterAsync(kotlin.Function1)`. | android |
| `https://developer.android.com/reference/kotlin/androidx/paging/PagingData<R>` | `<T : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html, R : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html> https://developer.android.com/reference/kotlin/androidx/paging/PagingData<T>.https://developer.android.com/reference/kotlin/androidx/paging/PagingData#(androidx.paging.PagingData).flatMapAsync(kotlin.Function1)( transform: (T) -> https://reactivex.io/RxJava/2.x/javadoc/io/reactivex/Single.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-iterable/index.html<R>> )` Returns a `https://developer.android.com/reference/kotlin/androidx/paging/PagingData` of all elements returned from applying the given `https://developer.android.com/reference/kotlin/androidx/paging/rxjava2/package-summary#(androidx.paging.PagingData).flatMapAsync(kotlin.Function1)` to each element, as it is loaded. | android |
| `https://developer.android.com/reference/kotlin/androidx/paging/PagingData<R>` | `<T : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html, R : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html> https://developer.android.com/reference/kotlin/androidx/paging/PagingData<T>.https://developer.android.com/reference/kotlin/androidx/paging/PagingData#(androidx.paging.PagingData).flatMapAsync(kotlin.Function1)( transform: (T) -> http://reactivex.io/RxJava/3.x/javadoc/io/reactivex/rxjava3/core/Single.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-iterable/index.html<R>> )` Returns a `https://developer.android.com/reference/kotlin/androidx/paging/PagingData` of all elements returned from applying the given `https://developer.android.com/reference/kotlin/androidx/paging/rxjava3/package-summary#(androidx.paging.PagingData).flatMapAsync(kotlin.Function1)` to each element, as it is loaded. | android |
| `https://developer.android.com/reference/kotlin/androidx/paging/PagingData<R>` | `<T : R, R : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html> https://developer.android.com/reference/kotlin/androidx/paging/PagingData<T>.https://developer.android.com/reference/kotlin/androidx/paging/PagingData#(androidx.paging.PagingData).insertSeparatorsAsync(kotlin.Function2)( generator: (T?, T?) -> https://reactivex.io/RxJava/2.x/javadoc/io/reactivex/Maybe.html<R> )` Returns a `https://developer.android.com/reference/kotlin/androidx/paging/PagingData` containing each original element, with an optional separator generated by `https://developer.android.com/reference/kotlin/androidx/paging/rxjava2/package-summary#(androidx.paging.PagingData).insertSeparatorsAsync(kotlin.Function2)`, given the elements before and after (or null, in boundary conditions). | android |
| `https://developer.android.com/reference/kotlin/androidx/paging/PagingData<R>` | `<T : R, R : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html> https://developer.android.com/reference/kotlin/androidx/paging/PagingData<T>.https://developer.android.com/reference/kotlin/androidx/paging/PagingData#(androidx.paging.PagingData).insertSeparatorsAsync(kotlin.Function2)( generator: (T?, T?) -> http://reactivex.io/RxJava/3.x/javadoc/io/reactivex/rxjava3/core/Maybe.html<R> )` Returns a `https://developer.android.com/reference/kotlin/androidx/paging/PagingData` containing each original element, with an optional separator generated by `https://developer.android.com/reference/kotlin/androidx/paging/rxjava3/package-summary#(androidx.paging.PagingData).insertSeparatorsAsync(kotlin.Function2)`, given the elements before and after (or null, in boundary conditions). | android |
| `https://developer.android.com/reference/kotlin/androidx/paging/PagingData<R>` | `<T : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html, R : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html> https://developer.android.com/reference/kotlin/androidx/paging/PagingData<T>.https://developer.android.com/reference/kotlin/androidx/paging/PagingData#(androidx.paging.PagingData).mapAsync(kotlin.Function1)(transform: (T) -> https://reactivex.io/RxJava/2.x/javadoc/io/reactivex/Single.html<R>)` Returns a `https://developer.android.com/reference/kotlin/androidx/paging/PagingData` containing the result of applying the given `https://developer.android.com/reference/kotlin/androidx/paging/rxjava2/package-summary#(androidx.paging.PagingData).mapAsync(kotlin.Function1)` to each element, as it is loaded. | android |
| `https://developer.android.com/reference/kotlin/androidx/paging/PagingData<R>` | `<T : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html, R : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html> https://developer.android.com/reference/kotlin/androidx/paging/PagingData<T>.https://developer.android.com/reference/kotlin/androidx/paging/PagingData#(androidx.paging.PagingData).mapAsync(kotlin.Function1)(transform: (T) -> http://reactivex.io/RxJava/3.x/javadoc/io/reactivex/rxjava3/core/Single.html<R>)` Returns a `https://developer.android.com/reference/kotlin/androidx/paging/PagingData` containing the result of applying the given `https://developer.android.com/reference/kotlin/androidx/paging/rxjava3/package-summary#(androidx.paging.PagingData).mapAsync(kotlin.Function1)` to each element, as it is loaded. | android |

## Public companion functions

### empty

Cmn Added in [3.0.0](https://developer.android.com/jetpack/androidx/releases/paging#3.0.0)

```
fun <T : Any> empty(): PagingData<T>
```

Create a `https://developer.android.com/reference/kotlin/androidx/paging/PagingData` that immediately displays an empty list of items when submitted to a presenter. E.g., androidx.paging.AsyncPagingDataAdapter and dispatches `https://developer.android.com/reference/kotlin/androidx/paging/LoadState.NotLoading` on all LoadStates to the presenter.

### empty

Cmn Added in [3.2.0](https://developer.android.com/jetpack/androidx/releases/paging#3.2.0)

```
fun <T : Any> empty(
    sourceLoadStates: LoadStates,
    mediatorLoadStates: LoadStates? = null
): PagingData<T>
```

Create a `https://developer.android.com/reference/kotlin/androidx/paging/PagingData` that immediately displays an empty list of items when submitted to a presenter. E.g., androidx.paging.AsyncPagingDataAdapter.

| Parameters |
|---|---|
| `sourceLoadStates: https://developer.android.com/reference/kotlin/androidx/paging/LoadStates` | `https://developer.android.com/reference/kotlin/androidx/paging/LoadStates` of `https://developer.android.com/reference/kotlin/androidx/paging/PagingSource` to pass forward to a presenter. E.g., androidx.paging.AsyncPagingDataAdapter. |
| `mediatorLoadStates: https://developer.android.com/reference/kotlin/androidx/paging/LoadStates? = null` | `https://developer.android.com/reference/kotlin/androidx/paging/LoadStates` of `https://developer.android.com/reference/kotlin/androidx/paging/RemoteMediator` to pass forward to a presenter. E.g., androidx.paging.AsyncPagingDataAdapter. |

### from

Cmn

```
fun <T : Any> from(
    data: List<T>,
    placeholdersBefore: Int = 0,
    placeholdersAfter: Int = 0
): PagingData<T>
```

Create a `https://developer.android.com/reference/kotlin/androidx/paging/PagingData` that immediately displays a static list of items when submitted to a presenter. E.g., androidx.paging.AsyncPagingDataAdapter and dispatches `https://developer.android.com/reference/kotlin/androidx/paging/LoadState.NotLoading` on all LoadStates to the presenter.

| Parameters |
|---|---|
| `data: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<T>` | Static list of `https://developer.android.com/reference/kotlin/androidx/paging/PagingData.Companion#from(kotlin.collections.List,kotlin.Int,kotlin.Int)` to display. |
| `placeholdersBefore: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html = 0` | The count of placeholders before the list of `https://developer.android.com/reference/kotlin/androidx/paging/PagingData.Companion#from(kotlin.collections.List,kotlin.Int,kotlin.Int)`. This can be used to display placeholders along with the static list of data. Note that these placeholders are no-op, meaning scrolls to these placeholders do not trigger loads. to these placeholders does not trigger loads. |
| `placeholdersAfter: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html = 0` | The count of placeholders after the list of `https://developer.android.com/reference/kotlin/androidx/paging/PagingData.Companion#from(kotlin.collections.List,kotlin.Int,kotlin.Int)`. This can be used to display placeholders along with the static list of data. Note that these placeholders are no-op, meaning scrolls to these placeholders do not trigger loads. |

### from

Cmn

```
fun <T : Any> from(
    data: List<T>,
    sourceLoadStates: LoadStates,
    mediatorLoadStates: LoadStates? = null,
    placeholdersBefore: Int = 0,
    placeholdersAfter: Int = 0
): PagingData<T>
```

Create a `https://developer.android.com/reference/kotlin/androidx/paging/PagingData` that immediately displays a static list of items when submitted to a presenter. E.g., androidx.paging.AsyncPagingDataAdapter.

| Parameters |
|---|---|
| `data: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<T>` | Static list of `https://developer.android.com/reference/kotlin/androidx/paging/PagingData.Companion#from(kotlin.collections.List,androidx.paging.LoadStates,androidx.paging.LoadStates,kotlin.Int,kotlin.Int)` to display. |
| `sourceLoadStates: https://developer.android.com/reference/kotlin/androidx/paging/LoadStates` | `https://developer.android.com/reference/kotlin/androidx/paging/LoadStates` of `https://developer.android.com/reference/kotlin/androidx/paging/PagingSource` to pass forward to a presenter. E.g., androidx.paging.AsyncPagingDataAdapter. |
| `mediatorLoadStates: https://developer.android.com/reference/kotlin/androidx/paging/LoadStates? = null` | `https://developer.android.com/reference/kotlin/androidx/paging/LoadStates` of `https://developer.android.com/reference/kotlin/androidx/paging/RemoteMediator` to pass forward to a presenter. E.g., androidx.paging.AsyncPagingDataAdapter. |
| `placeholdersBefore: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html = 0` | The count of placeholders before the list of `https://developer.android.com/reference/kotlin/androidx/paging/PagingData.Companion#from(kotlin.collections.List,androidx.paging.LoadStates,androidx.paging.LoadStates,kotlin.Int,kotlin.Int)`. This can be used to display placeholders along with the static list of data. Note that these placeholders are no-op, meaning scrolls to these placeholders do not trigger loads. to these placeholders does not trigger loads. |
| `placeholdersAfter: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html = 0` | The count of placeholders after the list of `https://developer.android.com/reference/kotlin/androidx/paging/PagingData.Companion#from(kotlin.collections.List,androidx.paging.LoadStates,androidx.paging.LoadStates,kotlin.Int,kotlin.Int)`. This can be used to display placeholders along with the static list of data. Note that these placeholders are no-op, meaning scrolls to these placeholders do not trigger loads. |

## Extension functions

### PagingData.filterAsync

android Artifact: [androidx.paging:paging-guava](https://developer.android.com/jetpack/androidx/releases/paging) [View Source](https://cs.android.com/search?q=file:androidx/paging/ListenableFuturePagingData.kt+function:filterAsync)

```
fun <T : Any> PagingData<T>.filterAsync(
    predicate: AsyncFunction<T, Boolean>,
    executor: Executor
): PagingData<T>
```

Returns a `https://developer.android.com/reference/kotlin/androidx/paging/PagingData` containing only elements matching the given `https://developer.android.com/reference/kotlin/androidx/paging/package-summary#(androidx.paging.PagingData).filterAsync(com.google.common.util.concurrent.AsyncFunction,java.util.concurrent.Executor)`.

| Parameters |
|---|---|
| `predicate: https://guava.dev/releases/snapshot-android/api/docs/com/google/common/util/concurrent/AsyncFunction.html<T, https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html>` | `https://guava.dev/releases/snapshot-android/api/docs/com/google/common/util/concurrent/AsyncFunction.html` returning `false` for unmatched items which should be filtered. |
| `executor: https://developer.android.com/reference/java/util/concurrent/Executor.html` | `https://developer.android.com/reference/java/util/concurrent/Executor.html` to run the `https://guava.dev/releases/snapshot-android/api/docs/com/google/common/util/concurrent/AsyncFunction.html` in. |

### PagingData.flatMapAsync

android Artifact: [androidx.paging:paging-guava](https://developer.android.com/jetpack/androidx/releases/paging) [View Source](https://cs.android.com/search?q=file:androidx/paging/ListenableFuturePagingData.kt+function:flatMapAsync)

```
fun <T : Any, R : Any> PagingData<T>.flatMapAsync(
    transform: AsyncFunction<T, Iterable<R>>,
    executor: Executor
): PagingData<R>
```

Returns a `https://developer.android.com/reference/kotlin/androidx/paging/PagingData` of all elements returned from applying the given `https://developer.android.com/reference/kotlin/androidx/paging/package-summary#(androidx.paging.PagingData).flatMapAsync(com.google.common.util.concurrent.AsyncFunction,java.util.concurrent.Executor)` to each element, as it is loaded.

| Parameters |
|---|---|
| `transform: https://guava.dev/releases/snapshot-android/api/docs/com/google/common/util/concurrent/AsyncFunction.html<T, https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-iterable/index.html<R>>` | `https://guava.dev/releases/snapshot-android/api/docs/com/google/common/util/concurrent/AsyncFunction.html` to transform an item of type `https://developer.android.com/reference/kotlin/androidx/paging/package-summary#(androidx.paging.PagingData).flatMapAsync(com.google.common.util.concurrent.AsyncFunction,java.util.concurrent.Executor)` a list of items of type `https://developer.android.com/reference/kotlin/androidx/paging/package-summary#(androidx.paging.PagingData).flatMapAsync(com.google.common.util.concurrent.AsyncFunction,java.util.concurrent.Executor)`. |
| `executor: https://developer.android.com/reference/java/util/concurrent/Executor.html` | `https://developer.android.com/reference/java/util/concurrent/Executor.html` to run the `https://guava.dev/releases/snapshot-android/api/docs/com/google/common/util/concurrent/AsyncFunction.html` in. |

### PagingData.insertSeparatorsAsync

android Artifact: [androidx.paging:paging-guava](https://developer.android.com/jetpack/androidx/releases/paging) [View Source](https://cs.android.com/search?q=file:androidx/paging/ListenableFuturePagingData.kt+function:insertSeparatorsAsync)

```
fun <T : R, R : Any> PagingData<T>.insertSeparatorsAsync(
    generator: AsyncFunction<AdjacentItems<T>, R?>,
    executor: Executor
): PagingData<R>
```

Returns a `https://developer.android.com/reference/kotlin/androidx/paging/PagingData` containing each original element, with an optional separator generated by `https://developer.android.com/reference/kotlin/androidx/paging/package-summary#(androidx.paging.PagingData).insertSeparatorsAsync(com.google.common.util.concurrent.AsyncFunction,java.util.concurrent.Executor)`, given the elements before and after (or null, in boundary conditions).

Note that this transform is applied asynchronously, as pages are loaded. Potential separators between pages are only computed once both pages are loaded.

```kotlin
import androidx.paging.AdjacentItems
import androidx.paging.insertSeparators
import androidx.paging.insertSeparatorsAsync
import androidx.paging.rxjava2.insertSeparatorsAsync

/*
 * Create letter separators in an alphabetically sorted list.
 *
 * For example, if the input is:
 *     "apple", "apricot", "banana", "carrot"
 *
 * The operator would output:
 *     "A", "apple", "apricot", "B", "banana", "C", "carrot"
 */
pagingDataStream.map { pagingData ->
    // map outer stream, so we can perform transformations on each paging generation
    pagingData.insertSeparatorsAsync(
        AsyncFunction<AdjacentItems<String>, String?> {
            Futures.submit(
                Callable<String?> {
                    val (before, after) = it!!
                    if (after != null && before?.first() != after.first()) {
                        // separator - after is first item that starts with its first letter
                        after.first().uppercaseChar().toString()
                    } else {
                        // no separator - either end of list, or first letters of before/after
                        // are the same
                        null
                    }
                },
                executor,
            )
        },
        executor,
    )
}
```

```kotlin
import androidx.paging.AdjacentItems
import androidx.paging.insertSeparators
import androidx.paging.insertSeparatorsAsync
import androidx.paging.map
import androidx.paging.rxjava2.insertSeparatorsAsync

open class UiModel
data class ItemUiModel(val item: Item) : UiModel()
data class SeparatorUiModel(val char: Char) : UiModel()

/*
 * Create letter separators in an alphabetically sorted list of Items, with UiModel objects.
 *
 * For example, if the input is (each an `Item`):
 *     "apple", "apricot", "banana", "carrot"
 *
 * The operator would output a list of UiModels corresponding to:
 *     "A", "apple", "apricot", "B", "banana", "C", "carrot"
 */
pagingDataStream.map { pagingData ->
    // map outer stream, so we can perform transformations on each paging generation
    pagingData
        .map { item ->
            ItemUiModel(item) // convert items in stream to ItemUiModel
        }
        .insertSeparatorsAsync(
            AsyncFunction<AdjacentItems<ItemUiModel>, UiModel?> {
                Futures.submit(
                    Callable<UiModel> {
                        val (before, after) = it!!
                        if (
                            after != null &&
                                before?.item?.label?.first() != after.item.label.first()
                        ) {
                            // separator - after is first item that starts with its first letter
                            SeparatorUiModel(after.item.label.first().uppercaseChar())
                        } else {
                            // no separator - either end of list, or first letters of
                            // before/after are the same
                            null
                        }
                    },
                    executor,
                )
            },
            executor,
        )
}
```

| Parameters |
|---|---|
| `generator: https://guava.dev/releases/snapshot-android/api/docs/com/google/common/util/concurrent/AsyncFunction.html<https://developer.android.com/reference/kotlin/androidx/paging/AdjacentItems<T>, R?>` | `https://guava.dev/releases/snapshot-android/api/docs/com/google/common/util/concurrent/AsyncFunction.html` used to generate separator between two `https://developer.android.com/reference/kotlin/androidx/paging/AdjacentItems` or the header or footer if either `https://developer.android.com/reference/kotlin/androidx/paging/AdjacentItems#before()` or `https://developer.android.com/reference/kotlin/androidx/paging/AdjacentItems#after()` is `null`. |
| `executor: https://developer.android.com/reference/java/util/concurrent/Executor.html` | `https://developer.android.com/reference/java/util/concurrent/Executor.html` to run the `https://guava.dev/releases/snapshot-android/api/docs/com/google/common/util/concurrent/AsyncFunction.html` in. |

### PagingData.mapAsync

android Artifact: [androidx.paging:paging-guava](https://developer.android.com/jetpack/androidx/releases/paging) [View Source](https://cs.android.com/search?q=file:androidx/paging/ListenableFuturePagingData.kt+function:mapAsync)

```
fun <T : Any, R : Any> PagingData<T>.mapAsync(
    transform: AsyncFunction<T, R>,
    executor: Executor
): PagingData<R>
```

Returns a `https://developer.android.com/reference/kotlin/androidx/paging/PagingData` containing the result of applying the given `https://developer.android.com/reference/kotlin/androidx/paging/package-summary#(androidx.paging.PagingData).mapAsync(com.google.common.util.concurrent.AsyncFunction,java.util.concurrent.Executor)` to each element, as it is loaded.

| Parameters |
|---|---|
| `transform: https://guava.dev/releases/snapshot-android/api/docs/com/google/common/util/concurrent/AsyncFunction.html<T, R>` | `https://guava.dev/releases/snapshot-android/api/docs/com/google/common/util/concurrent/AsyncFunction.html` to transform an item of type `https://developer.android.com/reference/kotlin/androidx/paging/package-summary#(androidx.paging.PagingData).mapAsync(com.google.common.util.concurrent.AsyncFunction,java.util.concurrent.Executor)` to `https://developer.android.com/reference/kotlin/androidx/paging/package-summary#(androidx.paging.PagingData).mapAsync(com.google.common.util.concurrent.AsyncFunction,java.util.concurrent.Executor)`. |
| `executor: https://developer.android.com/reference/java/util/concurrent/Executor.html` | `https://developer.android.com/reference/java/util/concurrent/Executor.html` to run the `https://guava.dev/releases/snapshot-android/api/docs/com/google/common/util/concurrent/AsyncFunction.html` in. |

### PagingData.filter

Cmn Artifact: [androidx.paging:paging-common](https://developer.android.com/jetpack/androidx/releases/paging) [View Source](https://cs.android.com/search?q=file:androidx/paging/PagingDataTransforms.kt+function:filter)

```
fun <T : Any> PagingData<T>.filter(predicate: suspend (T) -> Boolean): PagingData<T>
```

Returns a `https://developer.android.com/reference/kotlin/androidx/paging/PagingData` containing only elements matching the given `https://developer.android.com/reference/kotlin/androidx/paging/package-summary#(androidx.paging.PagingData).filter(kotlin.coroutines.SuspendFunction1)`

### PagingData.filter

android Artifact: [androidx.paging:paging-common](https://developer.android.com/jetpack/androidx/releases/paging) [View Source](https://cs.android.com/search?q=file:androidx/paging/PagingDataTransforms.jvm.kt+function:filter)

```
fun <T : Any> PagingData<T>.filter(executor: Executor, predicate: (T) -> Boolean): PagingData<T>
```

Returns a `https://developer.android.com/reference/kotlin/androidx/paging/PagingData` containing only elements matching the given `https://developer.android.com/reference/kotlin/androidx/paging/package-summary#(androidx.paging.PagingData).filter(java.util.concurrent.Executor,kotlin.Function1)`.

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/paging/package-summary#(androidx.paging.PagingData).filter(java.util.concurrent.Executor,kotlin.Function1)` |   |

### PagingData.flatMap

Cmn Artifact: [androidx.paging:paging-common](https://developer.android.com/jetpack/androidx/releases/paging) [View Source](https://cs.android.com/search?q=file:androidx/paging/PagingDataTransforms.kt+function:flatMap)

```
fun <T : Any, R : Any> PagingData<T>.flatMap(transform: suspend (T) -> Iterable<R>): PagingData<R>
```

Returns a `https://developer.android.com/reference/kotlin/androidx/paging/PagingData` of all elements returned from applying the given `https://developer.android.com/reference/kotlin/androidx/paging/package-summary#(androidx.paging.PagingData).flatMap(kotlin.coroutines.SuspendFunction1)` to each element, as it is loaded.

### PagingData.flatMap

android Artifact: [androidx.paging:paging-common](https://developer.android.com/jetpack/androidx/releases/paging) [View Source](https://cs.android.com/search?q=file:androidx/paging/PagingDataTransforms.jvm.kt+function:flatMap)

```
fun <T : Any, R : Any> PagingData<T>.flatMap(
    executor: Executor,
    transform: (T) -> Iterable<R>
): PagingData<R>
```

Returns a `https://developer.android.com/reference/kotlin/androidx/paging/PagingData` of all elements returned from applying the given `https://developer.android.com/reference/kotlin/androidx/paging/package-summary#(androidx.paging.PagingData).flatMap(java.util.concurrent.Executor,kotlin.Function1)` to each element, as it is loaded.

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/paging/package-summary#(androidx.paging.PagingData).flatMap(java.util.concurrent.Executor,kotlin.Function1)` |   |

### PagingData.insertFooterItem

Cmn Artifact: [androidx.paging:paging-common](https://developer.android.com/jetpack/androidx/releases/paging) [View Source](https://cs.android.com/search?q=file:androidx/paging/PagingDataTransforms.kt+function:insertFooterItem)

```
fun <T : Any> PagingData<T>.insertFooterItem(
    terminalSeparatorType: TerminalSeparatorType = FULLY_COMPLETE,
    item: T
): PagingData<T>
```

Returns a `https://developer.android.com/reference/kotlin/androidx/paging/PagingData` containing each original element, with the passed footer `https://developer.android.com/reference/kotlin/androidx/paging/package-summary#(androidx.paging.PagingData).insertFooterItem(androidx.paging.TerminalSeparatorType,kotlin.Any)` added to the end of the list.

The footer `https://developer.android.com/reference/kotlin/androidx/paging/package-summary#(androidx.paging.PagingData).insertFooterItem(androidx.paging.TerminalSeparatorType,kotlin.Any)` is added to a loaded page which marks the end of the data stream in the `https://developer.android.com/reference/kotlin/androidx/paging/LoadType#APPEND` direction, either by returning null in `https://developer.android.com/reference/kotlin/androidx/paging/PagingSource.LoadResult.Page#nextKey()`. It will be removed if the last page in the list is dropped, which can happen in the case of loaded pages exceeding `https://developer.android.com/reference/kotlin/androidx/paging/PagingConfig#maxSize()`.

Note: This operation is not idempotent, calling it multiple times will continually add more footers to the end of the list, which can be useful if multiple footer items are required.

| Parameters |
|---|---|
| `terminalSeparatorType: https://developer.android.com/reference/kotlin/androidx/paging/TerminalSeparatorType = FULLY_COMPLETE` | `https://developer.android.com/reference/kotlin/androidx/paging/TerminalSeparatorType` used to configure when the header and footer are added. |
| `item: T` | The footer to add to the end of the list once it is fully loaded in the `https://developer.android.com/reference/kotlin/androidx/paging/LoadType#APPEND` direction. |

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/paging/package-summary#(androidx.paging.PagingData).insertHeaderItem(androidx.paging.TerminalSeparatorType,kotlin.Any)` |   |

### PagingData.insertHeaderItem

Cmn Artifact: [androidx.paging:paging-common](https://developer.android.com/jetpack/androidx/releases/paging) [View Source](https://cs.android.com/search?q=file:androidx/paging/PagingDataTransforms.kt+function:insertHeaderItem)

```
fun <T : Any> PagingData<T>.insertHeaderItem(
    terminalSeparatorType: TerminalSeparatorType = FULLY_COMPLETE,
    item: T
): PagingData<T>
```

Returns a `https://developer.android.com/reference/kotlin/androidx/paging/PagingData` containing each original element, with the passed header `https://developer.android.com/reference/kotlin/androidx/paging/package-summary#(androidx.paging.PagingData).insertHeaderItem(androidx.paging.TerminalSeparatorType,kotlin.Any)` added to the start of the list.

The header `https://developer.android.com/reference/kotlin/androidx/paging/package-summary#(androidx.paging.PagingData).insertHeaderItem(androidx.paging.TerminalSeparatorType,kotlin.Any)` is added to a loaded page which marks the end of the data stream in the `https://developer.android.com/reference/kotlin/androidx/paging/LoadType#PREPEND` direction by returning null in `https://developer.android.com/reference/kotlin/androidx/paging/PagingSource.LoadResult.Page#prevKey()`. It will be removed if the first page in the list is dropped, which can happen in the case of loaded pages exceeding `https://developer.android.com/reference/kotlin/androidx/paging/PagingConfig#maxSize()`.

Note: This operation is not idempotent, calling it multiple times will continually add more headers to the start of the list, which can be useful if multiple header items are required.

| Parameters |
|---|---|
| `terminalSeparatorType: https://developer.android.com/reference/kotlin/androidx/paging/TerminalSeparatorType = FULLY_COMPLETE` | `https://developer.android.com/reference/kotlin/androidx/paging/TerminalSeparatorType` used to configure when the header and footer are added. |
| `item: T` | The header to add to the front of the list once it is fully loaded in the `https://developer.android.com/reference/kotlin/androidx/paging/LoadType#PREPEND` direction. |

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/paging/package-summary#(androidx.paging.PagingData).insertFooterItem(androidx.paging.TerminalSeparatorType,kotlin.Any)` |   |

### PagingData.insertSeparators

Cmn Artifact: [androidx.paging:paging-common](https://developer.android.com/jetpack/androidx/releases/paging) [View Source](https://cs.android.com/search?q=file:androidx/paging/PagingDataTransforms.kt+function:insertSeparators)

```
fun <T : R, R : Any> PagingData<T>.insertSeparators(
    terminalSeparatorType: TerminalSeparatorType = FULLY_COMPLETE,
    generator: suspend (T?, T?) -> R?
): PagingData<R>
```

Returns a `https://developer.android.com/reference/kotlin/androidx/paging/PagingData` containing each original element, with an optional separator generated by `https://developer.android.com/reference/kotlin/androidx/paging/package-summary#(androidx.paging.PagingData).insertSeparators(androidx.paging.TerminalSeparatorType,kotlin.coroutines.SuspendFunction2)`, given the elements before and after (or null, in boundary conditions).

Note that this transform is applied asynchronously, as pages are loaded. Potential separators between pages are only computed once both pages are loaded.

```kotlin
import androidx.paging.insertSeparators

/*
 * Create letter separators in an alphabetically sorted list.
 *
 * For example, if the input is:
 *     "apple", "apricot", "banana", "carrot"
 *
 * The operator would output:
 *     "A", "apple", "apricot", "B", "banana", "C", "carrot"
 */
pagingDataStream.map { pagingData ->
    // map outer stream, so we can perform transformations on each paging generation
    pagingData.insertSeparators { before: String?, after: String? ->
        if (after != null && before?.first() != after.first()) {
            // separator - after is first item that starts with its first letter
            after.first().uppercaseChar().toString()
        } else {
            // no separator - either end of list, or first letters of before/after are the same
            null
        }
    }
}
```

```kotlin
import androidx.paging.insertSeparators
import androidx.paging.map

open class UiModel
data class ItemUiModel(val item: Item) : UiModel()
data class SeparatorUiModel(val char: Char) : UiModel()

/*
 * Create letter separators in an alphabetically sorted list of Items, with UiModel objects.
 *
 * For example, if the input is (each an `Item`):
 *     "apple", "apricot", "banana", "carrot"
 *
 * The operator would output a list of UiModels corresponding to:
 *     "A", "apple", "apricot", "B", "banana", "C", "carrot"
 */
pagingDataStream.map { pagingData ->
    // map outer stream, so we can perform transformations on each paging generation
    pagingData
        .map { item ->
            ItemUiModel(item) // convert items in stream to ItemUiModel
        }
        .insertSeparators<ItemUiModel, UiModel> { before: ItemUiModel?, after: ItemUiModel? ->
            if (after != null && before?.item?.label?.first() != after.item.label.first()) {
                // separator - after is first item that starts with its first letter
                SeparatorUiModel(after.item.label.first().uppercaseChar())
            } else {
                // no separator - either end of list, or first letters of before/after are the
                // same
                null
            }
        }
}
```

| Parameters |
|---|---|
| `terminalSeparatorType: https://developer.android.com/reference/kotlin/androidx/paging/TerminalSeparatorType = FULLY_COMPLETE` | `https://developer.android.com/reference/kotlin/androidx/paging/TerminalSeparatorType` used to configure when the header and footer are added. |
| `generator: suspend (T?, T?) -> R?` | Generator function used to construct a separator item given the item before and the item after. For terminal separators (header and footer), the arguments passed to the generator, `before` and `after`, will be `null` respectively. In cases where the fully paginated list is empty, a single separator will be added where both `before` and `after` items are `null`. |

### PagingData.insertSeparators

android Artifact: [androidx.paging:paging-common](https://developer.android.com/jetpack/androidx/releases/paging) [View Source](https://cs.android.com/search?q=file:androidx/paging/PagingDataTransforms.jvm.kt+function:insertSeparators)

```
fun <R : Any, T : R> PagingData<T>.insertSeparators(
    terminalSeparatorType: TerminalSeparatorType = TerminalSeparatorType.FULLY_COMPLETE,
    executor: Executor,
    generator: (T?, T?) -> R?
): PagingData<R>
```

Returns a `https://developer.android.com/reference/kotlin/androidx/paging/PagingData` containing each original element, with an optional separator generated by `https://developer.android.com/reference/kotlin/androidx/paging/package-summary#(androidx.paging.PagingData).insertSeparators(androidx.paging.TerminalSeparatorType,java.util.concurrent.Executor,kotlin.Function2)`, given the elements before and after (or null, in boundary conditions).

Note that this transform is applied asynchronously, as pages are loaded. Potential separators between pages are only computed once both pages are loaded.

**Kotlin callers should instead use the suspending extension function variant of insertSeparators**

```kotlin
/*
 * Create letter separators in an alphabetically sorted list.
 *
 * For example, if the input is:
 *     "apple", "apricot", "banana", "carrot"
 *
 * The operator would output:
 *     "A", "apple", "apricot", "B", "banana", "C", "carrot"
*/
pagingDataStream.map(pagingData ->
        // map outer stream, so we can perform transformations on each paging generation
        PagingDataTransforms.insertSeparators(pagingData, bgExecutor,
                (@Nullable String before, @Nullable String after) -> {
                    if (after != null && (before == null
                            || before.charAt(0) != after.charAt(0))) {
                        // separator - after is first item that starts with its first
                        // letter
                        return Character.toString(
                                Character.toUpperCase(after.charAt(0)));
                    } else {
                        // no separator - either end of list, or first
                        // letters of items are the same
                        return null;
                    }
                }));

/*
 * Create letter separators in an alphabetically sorted list of Items, with UiModel
 * objects.
 *
 * For example, if the input is (each an `Item`):
 *     "apple", "apricot", "banana", "carrot"
 *
 * The operator would output a list of UiModels corresponding to:
 *     "A", "apple", "apricot", "B", "banana", "C", "carrot"
*/
pagingDataStream.map(itemPagingData -> {
    // map outer stream, so we can perform transformations on each paging generation

    // first convert items in stream to UiModel.Item
    PagingData<UiModel.ItemModel> itemModelPagingData = PagingDataTransforms.map(
            itemPagingData, bgExecutor, UiModel.ItemModel::new);

    // Now insert UiModel.Separators, which makes the PagingData of generic type UiModel
    return PagingDataTransforms.insertSeparators(
            itemModelPagingData, bgExecutor,
            (@Nullable UiModel.ItemModel before, @Nullable UiModel.ItemModel after) -> {
                if (after != null && (before == null
                        || before.item.label.charAt(0) != after.item.label.charAt(0))) {
                    // separator - after is first item that starts with its first letter
                    return new UiModel.SeparatorModel(
                            Character.toUpperCase(after.item.label.charAt(0)));
                } else {
                    // no separator - either end of list, or first
                    // letters of items are the same
                    return null;
                }
            });
});

public class UiModel {
    static class ItemModel extends UiModel {
        public Item item;
        ItemModel(Item item) {
            this.item = item;
        }
    }
    static class SeparatorModel extends UiModel {
        public char character;
        SeparatorModel(char character) {
            this.character = character;
        }
    }
}
```

| Parameters |
|---|---|
| `terminalSeparatorType: https://developer.android.com/reference/kotlin/androidx/paging/TerminalSeparatorType = TerminalSeparatorType.FULLY_COMPLETE` | `https://developer.android.com/reference/kotlin/androidx/paging/TerminalSeparatorType` used to configure when the header and footer are added. |
| `executor: https://developer.android.com/reference/java/util/concurrent/Executor.html` | `https://developer.android.com/reference/java/util/concurrent/Executor.html` to run the `https://developer.android.com/reference/kotlin/androidx/paging/package-summary#(androidx.paging.PagingData).insertSeparators(androidx.paging.TerminalSeparatorType,java.util.concurrent.Executor,kotlin.Function2)` function in. |
| `generator: (T?, T?) -> R?` | Generator function used to construct a separator item given the item before and the item after. For terminal separators (header and footer), the arguments passed to the generator, `before` and `after`, will be `null` respectively. In cases where the fully paginated list is empty, a single separator will be added where both `before` and `after` items are `null`. |

### PagingData.map

Cmn Artifact: [androidx.paging:paging-common](https://developer.android.com/jetpack/androidx/releases/paging) [View Source](https://cs.android.com/search?q=file:androidx/paging/PagingDataTransforms.kt+function:map)

```
fun <T : Any, R : Any> PagingData<T>.map(transform: suspend (T) -> R): PagingData<R>
```

Returns a `https://developer.android.com/reference/kotlin/androidx/paging/PagingData` containing the result of applying the given `https://developer.android.com/reference/kotlin/androidx/paging/package-summary#(androidx.paging.PagingData).map(kotlin.coroutines.SuspendFunction1)` to each element, as it is loaded.

### PagingData.map

android Artifact: [androidx.paging:paging-common](https://developer.android.com/jetpack/androidx/releases/paging) [View Source](https://cs.android.com/search?q=file:androidx/paging/PagingDataTransforms.jvm.kt+function:map)

```
fun <T : Any, R : Any> PagingData<T>.map(executor: Executor, transform: (T) -> R): PagingData<R>
```

Returns a `https://developer.android.com/reference/kotlin/androidx/paging/PagingData` containing the result of applying the given `https://developer.android.com/reference/kotlin/androidx/paging/package-summary#(androidx.paging.PagingData).map(java.util.concurrent.Executor,kotlin.Function1)` to each element, as it is loaded.

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/paging/package-summary#(androidx.paging.PagingData).map(java.util.concurrent.Executor,kotlin.Function1)` |   |

### PagingData.filterAsync

android Artifact: [androidx.paging:paging-rxjava2](https://developer.android.com/jetpack/androidx/releases/paging) [View Source](https://cs.android.com/search?q=file:androidx/paging/rxjava2/RxPagingData.kt+function:filterAsync)

```
fun <T : Any> PagingData<T>.filterAsync(predicate: (T) -> Single<Boolean>): PagingData<T>
```

Returns a `https://developer.android.com/reference/kotlin/androidx/paging/PagingData` containing only elements matching the given `https://developer.android.com/reference/kotlin/androidx/paging/rxjava2/package-summary#(androidx.paging.PagingData).filterAsync(kotlin.Function1)`.

### PagingData.filterAsync

android Artifact: [androidx.paging:paging-rxjava3](https://developer.android.com/jetpack/androidx/releases/paging) [View Source](https://cs.android.com/search?q=file:androidx/paging/rxjava3/RxPagingData.kt+function:filterAsync)

```
fun <T : Any> PagingData<T>.filterAsync(predicate: (T) -> Single<Boolean>): PagingData<T>
```

Returns a `https://developer.android.com/reference/kotlin/androidx/paging/PagingData` containing only elements matching the given `https://developer.android.com/reference/kotlin/androidx/paging/rxjava3/package-summary#(androidx.paging.PagingData).filterAsync(kotlin.Function1)`.

### PagingData.flatMapAsync

android Artifact: [androidx.paging:paging-rxjava2](https://developer.android.com/jetpack/androidx/releases/paging) [View Source](https://cs.android.com/search?q=file:androidx/paging/rxjava2/RxPagingData.kt+function:flatMapAsync)

```
fun <T : Any, R : Any> PagingData<T>.flatMapAsync(
    transform: (T) -> Single<Iterable<R>>
): PagingData<R>
```

Returns a `https://developer.android.com/reference/kotlin/androidx/paging/PagingData` of all elements returned from applying the given `https://developer.android.com/reference/kotlin/androidx/paging/rxjava2/package-summary#(androidx.paging.PagingData).flatMapAsync(kotlin.Function1)` to each element, as it is loaded.

### PagingData.flatMapAsync

android Artifact: [androidx.paging:paging-rxjava3](https://developer.android.com/jetpack/androidx/releases/paging) [View Source](https://cs.android.com/search?q=file:androidx/paging/rxjava3/RxPagingData.kt+function:flatMapAsync)

```
fun <T : Any, R : Any> PagingData<T>.flatMapAsync(
    transform: (T) -> Single<Iterable<R>>
): PagingData<R>
```

Returns a `https://developer.android.com/reference/kotlin/androidx/paging/PagingData` of all elements returned from applying the given `https://developer.android.com/reference/kotlin/androidx/paging/rxjava3/package-summary#(androidx.paging.PagingData).flatMapAsync(kotlin.Function1)` to each element, as it is loaded.

### PagingData.insertSeparatorsAsync

android Artifact: [androidx.paging:paging-rxjava2](https://developer.android.com/jetpack/androidx/releases/paging) [View Source](https://cs.android.com/search?q=file:androidx/paging/rxjava2/RxPagingData.kt+function:insertSeparatorsAsync)

```
fun <T : R, R : Any> PagingData<T>.insertSeparatorsAsync(
    generator: (T?, T?) -> Maybe<R>
): PagingData<R>
```

Returns a `https://developer.android.com/reference/kotlin/androidx/paging/PagingData` containing each original element, with an optional separator generated by `https://developer.android.com/reference/kotlin/androidx/paging/rxjava2/package-summary#(androidx.paging.PagingData).insertSeparatorsAsync(kotlin.Function2)`, given the elements before and after (or null, in boundary conditions).

Note that this transform is applied asynchronously, as pages are loaded. Potential separators between pages are only computed once both pages are loaded.

```kotlin
import androidx.paging.insertSeparators
import androidx.paging.insertSeparatorsAsync
import androidx.paging.rxjava2.insertSeparatorsAsync

/*
 * Create letter separators in an alphabetically sorted list.
 *
 * For example, if the input is:
 *     "apple", "apricot", "banana", "carrot"
 *
 * The operator would output:
 *     "A", "apple", "apricot", "B", "banana", "C", "carrot"
 */
pagingDataStream.map { pagingData ->
    // map outer stream, so we can perform transformations on each paging generation
    pagingData.insertSeparatorsAsync { before: String?, after: String? ->
        Maybe.fromCallable<String> {
                if (after != null && before?.first() != after.first()) {
                    // separator - after is first item that starts with its first letter
                    after.first().uppercaseChar().toString()
                } else {
                    // no separator - either end of list, or first letters of before/after are
                    // the same
                    null
                }
            }
            .subscribeOn(Schedulers.computation())
    }
}
```

```kotlin
import androidx.paging.insertSeparators
import androidx.paging.insertSeparatorsAsync
import androidx.paging.map
import androidx.paging.rxjava2.insertSeparatorsAsync

open class UiModel
data class ItemUiModel(val item: Item) : UiModel()
data class SeparatorUiModel(val char: Char) : UiModel()

/*
 * Create letter separators in an alphabetically sorted list of Items, with UiModel objects.
 *
 * For example, if the input is (each an `Item`):
 *     "apple", "apricot", "banana", "carrot"
 *
 * The operator would output a list of UiModels corresponding to:
 *     "A", "apple", "apricot", "B", "banana", "C", "carrot"
 */
pagingDataStream.map { pagingData ->
    // map outer stream, so we can perform transformations on each paging generation
    pagingData
        .map { item ->
            ItemUiModel(item) // convert items in stream to ItemUiModel
        }
        .insertSeparatorsAsync { before: ItemUiModel?, after: ItemUiModel? ->
            Maybe.fromCallable<UiModel> {
                    if (
                        after != null &&
                            before?.item?.label?.first() != after.item.label.first()
                    ) {
                        // separator - after is first item that starts with its first letter
                        SeparatorUiModel(after.item.label.first().uppercaseChar())
                    } else {
                        // no separator - either end of list, or first letters of before/after
                        // are the same
                        null
                    }
                }
                .subscribeOn(Schedulers.computation())
        }
}
```

### PagingData.insertSeparatorsAsync

android Artifact: [androidx.paging:paging-rxjava3](https://developer.android.com/jetpack/androidx/releases/paging) [View Source](https://cs.android.com/search?q=file:androidx/paging/rxjava3/RxPagingData.kt+function:insertSeparatorsAsync)

```
fun <T : R, R : Any> PagingData<T>.insertSeparatorsAsync(
    generator: (T?, T?) -> Maybe<R>
): PagingData<R>
```

Returns a `https://developer.android.com/reference/kotlin/androidx/paging/PagingData` containing each original element, with an optional separator generated by `https://developer.android.com/reference/kotlin/androidx/paging/rxjava3/package-summary#(androidx.paging.PagingData).insertSeparatorsAsync(kotlin.Function2)`, given the elements before and after (or null, in boundary conditions).

Note that this transform is applied asynchronously, as pages are loaded. Potential separators between pages are only computed once both pages are loaded.

```kotlin
import androidx.paging.insertSeparators
import androidx.paging.insertSeparatorsAsync
import androidx.paging.rxjava2.insertSeparatorsAsync

/*
 * Create letter separators in an alphabetically sorted list.
 *
 * For example, if the input is:
 *     "apple", "apricot", "banana", "carrot"
 *
 * The operator would output:
 *     "A", "apple", "apricot", "B", "banana", "C", "carrot"
 */
pagingDataStream.map { pagingData ->
    // map outer stream, so we can perform transformations on each paging generation
    pagingData.insertSeparatorsAsync { before: String?, after: String? ->
        Maybe.fromCallable<String> {
                if (after != null && before?.first() != after.first()) {
                    // separator - after is first item that starts with its first letter
                    after.first().uppercaseChar().toString()
                } else {
                    // no separator - either end of list, or first letters of before/after are
                    // the same
                    null
                }
            }
            .subscribeOn(Schedulers.computation())
    }
}
```

```kotlin
import androidx.paging.insertSeparators
import androidx.paging.insertSeparatorsAsync
import androidx.paging.map
import androidx.paging.rxjava2.insertSeparatorsAsync

open class UiModel
data class ItemUiModel(val item: Item) : UiModel()
data class SeparatorUiModel(val char: Char) : UiModel()

/*
 * Create letter separators in an alphabetically sorted list of Items, with UiModel objects.
 *
 * For example, if the input is (each an `Item`):
 *     "apple", "apricot", "banana", "carrot"
 *
 * The operator would output a list of UiModels corresponding to:
 *     "A", "apple", "apricot", "B", "banana", "C", "carrot"
 */
pagingDataStream.map { pagingData ->
    // map outer stream, so we can perform transformations on each paging generation
    pagingData
        .map { item ->
            ItemUiModel(item) // convert items in stream to ItemUiModel
        }
        .insertSeparatorsAsync { before: ItemUiModel?, after: ItemUiModel? ->
            Maybe.fromCallable<UiModel> {
                    if (
                        after != null &&
                            before?.item?.label?.first() != after.item.label.first()
                    ) {
                        // separator - after is first item that starts with its first letter
                        SeparatorUiModel(after.item.label.first().uppercaseChar())
                    } else {
                        // no separator - either end of list, or first letters of before/after
                        // are the same
                        null
                    }
                }
                .subscribeOn(Schedulers.computation())
        }
}
```

### PagingData.mapAsync

android Artifact: [androidx.paging:paging-rxjava2](https://developer.android.com/jetpack/androidx/releases/paging) [View Source](https://cs.android.com/search?q=file:androidx/paging/rxjava2/RxPagingData.kt+function:mapAsync)

```
fun <T : Any, R : Any> PagingData<T>.mapAsync(transform: (T) -> Single<R>): PagingData<R>
```

Returns a `https://developer.android.com/reference/kotlin/androidx/paging/PagingData` containing the result of applying the given `https://developer.android.com/reference/kotlin/androidx/paging/rxjava2/package-summary#(androidx.paging.PagingData).mapAsync(kotlin.Function1)` to each element, as it is loaded.

### PagingData.mapAsync

android Artifact: [androidx.paging:paging-rxjava3](https://developer.android.com/jetpack/androidx/releases/paging) [View Source](https://cs.android.com/search?q=file:androidx/paging/rxjava3/RxPagingData.kt+function:mapAsync)

```
fun <T : Any, R : Any> PagingData<T>.mapAsync(transform: (T) -> Single<R>): PagingData<R>
```

Returns a `https://developer.android.com/reference/kotlin/androidx/paging/PagingData` containing the result of applying the given `https://developer.android.com/reference/kotlin/androidx/paging/rxjava3/package-summary#(androidx.paging.PagingData).mapAsync(kotlin.Function1)` to each element, as it is loaded.