# PagingDataFutures

Added in 3.0.0

*** ** * ** ***

<br />

```
public final class PagingDataFutures
```

<br />

*** ** * ** ***

## Summary

| ### Public methods |
|---|---|
| `static final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/paging/PagingData<@https://developer.android.com/reference/androidx/annotation/NonNull T>` | `<T extends https://developer.android.com/reference/java/lang/Object.html> https://developer.android.com/reference/androidx/paging/PagingDataFutures#(androidx.paging.PagingData).filter(com.google.common.util.concurrent.AsyncFunction,java.util.concurrent.Executor)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/paging/PagingData<@https://developer.android.com/reference/androidx/annotation/NonNull T> receiver, @https://developer.android.com/reference/androidx/annotation/NonNull https://guava.dev/releases/snapshot-android/api/docs/com/google/common/util/concurrent/AsyncFunction.html<@https://developer.android.com/reference/androidx/annotation/NonNull T, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/Boolean.html> predicate, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/concurrent/Executor.html executor )` Returns a `https://developer.android.com/reference/androidx/paging/PagingData` containing only elements matching the given `https://developer.android.com/reference/androidx/paging/package-summary#(androidx.paging.PagingData).filterAsync(com.google.common.util.concurrent.AsyncFunction,java.util.concurrent.Executor)`. |
| `static final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/paging/PagingData<@https://developer.android.com/reference/androidx/annotation/NonNull R>` | `<T extends https://developer.android.com/reference/java/lang/Object.html, R extends https://developer.android.com/reference/java/lang/Object.html> https://developer.android.com/reference/androidx/paging/PagingDataFutures#(androidx.paging.PagingData).flatMap(com.google.common.util.concurrent.AsyncFunction,java.util.concurrent.Executor)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/paging/PagingData<@https://developer.android.com/reference/androidx/annotation/NonNull T> receiver, @https://developer.android.com/reference/androidx/annotation/NonNull https://guava.dev/releases/snapshot-android/api/docs/com/google/common/util/concurrent/AsyncFunction.html<@https://developer.android.com/reference/androidx/annotation/NonNull T, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/Iterable.html<@https://developer.android.com/reference/androidx/annotation/NonNull R>> transform, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/concurrent/Executor.html executor )` Returns a `https://developer.android.com/reference/androidx/paging/PagingData` of all elements returned from applying the given `https://developer.android.com/reference/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. |
| `static final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/paging/PagingData<@https://developer.android.com/reference/androidx/annotation/NonNull R>` | `<T extends R, R extends https://developer.android.com/reference/java/lang/Object.html> https://developer.android.com/reference/androidx/paging/PagingDataFutures#(androidx.paging.PagingData).insertSeparators(com.google.common.util.concurrent.AsyncFunction,java.util.concurrent.Executor)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/paging/PagingData<@https://developer.android.com/reference/androidx/annotation/NonNull T> receiver, @https://developer.android.com/reference/androidx/annotation/NonNull https://guava.dev/releases/snapshot-android/api/docs/com/google/common/util/concurrent/AsyncFunction.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/paging/AdjacentItems<@https://developer.android.com/reference/androidx/annotation/NonNull T>, R> generator, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/concurrent/Executor.html executor )` Returns a `https://developer.android.com/reference/androidx/paging/PagingData` containing each original element, with an optional separator generated by `https://developer.android.com/reference/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). |
| `static final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/paging/PagingData<@https://developer.android.com/reference/androidx/annotation/NonNull R>` | `<T extends https://developer.android.com/reference/java/lang/Object.html, R extends https://developer.android.com/reference/java/lang/Object.html> https://developer.android.com/reference/androidx/paging/PagingDataFutures#(androidx.paging.PagingData).map(com.google.common.util.concurrent.AsyncFunction,java.util.concurrent.Executor)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/paging/PagingData<@https://developer.android.com/reference/androidx/annotation/NonNull T> receiver, @https://developer.android.com/reference/androidx/annotation/NonNull https://guava.dev/releases/snapshot-android/api/docs/com/google/common/util/concurrent/AsyncFunction.html<@https://developer.android.com/reference/androidx/annotation/NonNull T, @https://developer.android.com/reference/androidx/annotation/NonNull R> transform, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/concurrent/Executor.html executor )` Returns a `https://developer.android.com/reference/androidx/paging/PagingData` containing the result of applying the given `https://developer.android.com/reference/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. |

## Public methods

### filter

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) Added in [3.0.0](https://developer.android.com/jetpack/androidx/releases/paging#3.0.0)

```
public static final @NonNull PagingData<@NonNull T> <T extends Object> filter(
    @NonNull PagingData<@NonNull T> receiver,
    @NonNull AsyncFunction<@NonNull T, @NonNull Boolean> predicate,
    @NonNull Executor executor
)
```

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

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://guava.dev/releases/snapshot-android/api/docs/com/google/common/util/concurrent/AsyncFunction.html<@https://developer.android.com/reference/androidx/annotation/NonNull T, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/Boolean.html> predicate` | `https://guava.dev/releases/snapshot-android/api/docs/com/google/common/util/concurrent/AsyncFunction.html` returning `false` for unmatched items which should be filtered. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/concurrent/Executor.html executor` | `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. |

### flatMap

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) Added in [3.0.0](https://developer.android.com/jetpack/androidx/releases/paging#3.0.0)

```
public static final @NonNull PagingData<@NonNull R> <T extends Object, R extends Object> flatMap(
    @NonNull PagingData<@NonNull T> receiver,
    @NonNull AsyncFunction<@NonNull T, @NonNull Iterable<@NonNull R>> transform,
    @NonNull Executor executor
)
```

Returns a `https://developer.android.com/reference/androidx/paging/PagingData` of all elements returned from applying the given `https://developer.android.com/reference/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 |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://guava.dev/releases/snapshot-android/api/docs/com/google/common/util/concurrent/AsyncFunction.html<@https://developer.android.com/reference/androidx/annotation/NonNull T, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/Iterable.html<@https://developer.android.com/reference/androidx/annotation/NonNull R>> transform` | `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/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/androidx/paging/package-summary#(androidx.paging.PagingData).flatMapAsync(com.google.common.util.concurrent.AsyncFunction,java.util.concurrent.Executor)`. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/concurrent/Executor.html executor` | `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. |

### insertSeparators

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) Added in [3.0.0](https://developer.android.com/jetpack/androidx/releases/paging#3.0.0)

```
public static final @NonNull PagingData<@NonNull R> <T extends R, R extends Object> insertSeparators(
    @NonNull PagingData<@NonNull T> receiver,
    @NonNull AsyncFunction<@NonNull AdjacentItems<@NonNull T>, R> generator,
    @NonNull Executor executor
)
```

Returns a `https://developer.android.com/reference/androidx/paging/PagingData` containing each original element, with an optional separator generated by `https://developer.android.com/reference/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 |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://guava.dev/releases/snapshot-android/api/docs/com/google/common/util/concurrent/AsyncFunction.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/paging/AdjacentItems<@https://developer.android.com/reference/androidx/annotation/NonNull T>, R> generator` | `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/androidx/paging/AdjacentItems` or the header or footer if either `https://developer.android.com/reference/androidx/paging/AdjacentItems#before()` or `https://developer.android.com/reference/androidx/paging/AdjacentItems#after()` is `null`. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/concurrent/Executor.html executor` | `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. |

### map

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) Added in [3.0.0](https://developer.android.com/jetpack/androidx/releases/paging#3.0.0)

```
public static final @NonNull PagingData<@NonNull R> <T extends Object, R extends Object> map(
    @NonNull PagingData<@NonNull T> receiver,
    @NonNull AsyncFunction<@NonNull T, @NonNull R> transform,
    @NonNull Executor executor
)
```

Returns a `https://developer.android.com/reference/androidx/paging/PagingData` containing the result of applying the given `https://developer.android.com/reference/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 |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://guava.dev/releases/snapshot-android/api/docs/com/google/common/util/concurrent/AsyncFunction.html<@https://developer.android.com/reference/androidx/annotation/NonNull T, @https://developer.android.com/reference/androidx/annotation/NonNull R> transform` | `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/androidx/paging/package-summary#(androidx.paging.PagingData).mapAsync(com.google.common.util.concurrent.AsyncFunction,java.util.concurrent.Executor)` to `https://developer.android.com/reference/androidx/paging/package-summary#(androidx.paging.PagingData).mapAsync(com.google.common.util.concurrent.AsyncFunction,java.util.concurrent.Executor)`. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/concurrent/Executor.html executor` | `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. |