blob: 3aebdafea10c76301bed6b3a71cf902a1c7b8070 [file] [log] [blame]
<html devsite="true">
<head>
<title>DataSource</title>
{% setvar book_path %}/reference/kotlin/androidx/_book.yaml{% endsetvar %}
{% include "_shared/_reference-head-tags.html" %}
</head>
<body>
<div id="metadata-info-block"></div>
<h1>DataSource</h1>
<p>
<pre>abstract class <a href="/reference/kotlin/androidx/paging/DataSource.html">DataSource</a>&lt;Key&nbsp;:&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html">Any</a>,&nbsp;Value&nbsp;:&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html">Any</a>&gt;</pre>
</p>
<div class="devsite-table-wrapper"><devsite-expandable><span class="expand-control jd-sumtable-subclasses">Known direct subclasses
<div class="showalways" id="subclasses-direct"><a href="/reference/kotlin/androidx/paging/ItemKeyedDataSource.html">ItemKeyedDataSource</a>, <a href="/reference/kotlin/androidx/paging/PageKeyedDataSource.html">PageKeyedDataSource</a>, <a href="/reference/kotlin/androidx/paging/PositionalDataSource.html">PositionalDataSource</a></div>
</span>
<div id="subclasses-direct-summary">
<div class="devsite-table-wrapper">
<table class="responsive">
<colgroup>
<col width="40%">
<col>
</colgroup>
<tbody class="list">
<tr>
<td width="40%"><code><a href="/reference/kotlin/androidx/paging/ItemKeyedDataSource.html">ItemKeyedDataSource</a></code></td>
<td>
<p><strong>This class is deprecated.</strong> ItemKeyedDataSource is deprecated and has been replaced by PagingSource</p>
</td>
</tr>
<tr>
<td width="40%"><code><a href="/reference/kotlin/androidx/paging/PageKeyedDataSource.html">PageKeyedDataSource</a></code></td>
<td>
<p><strong>This class is deprecated.</strong> PageKeyedDataSource is deprecated and has been replaced by PagingSource</p>
</td>
</tr>
<tr>
<td width="40%"><code><a href="/reference/kotlin/androidx/paging/PositionalDataSource.html">PositionalDataSource</a></code></td>
<td>
<p><strong>This class is deprecated.</strong> PositionalDataSource is deprecated and has been replaced by PagingSource</p>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</devsite-expandable> </div>
<hr>
<p>Base class for loading pages of snapshot data into a <code><a href="/reference/kotlin/androidx/paging/PagedList.html">PagedList</a></code>.</p>
<p>DataSource is queried to load pages of content into a <code><a href="/reference/kotlin/androidx/paging/PagedList.html">PagedList</a></code>. A PagedList can grow as it loads more data, but the data loaded cannot be updated. If the underlying data set is modified, a new PagedList / DataSource pair must be created to represent the new data.</p>
<h3> Loading Pages</h3>
<p>PagedList queries data from its DataSource in response to loading hints. PagedListAdapter calls <code><a href="/reference/kotlin/androidx/paging/PagedList.html#loadAround(kotlin.Int)">PagedList.loadAround</a></code> to load content as the user scrolls in a RecyclerView.</p>
<p>To control how and when a PagedList queries data from its DataSource, see <code><a href="/reference/kotlin/androidx/paging/PagedList.Config.html">PagedList.Config</a></code>. The Config object defines things like load sizes and prefetch distance.</p>
<h3> Updating Paged Data</h3>
<p>A PagedList / DataSource pair are a snapshot of the data set. A new pair of PagedList / DataSource must be created if an update occurs, such as a reorder, insert, delete, or content update occurs. A DataSource must detect that it cannot continue loading its snapshot (for instance, when Database query notices a table being invalidated), and call <code><a href="/reference/kotlin/androidx/paging/DataSource.html#invalidate()">invalidate</a></code>. Then a new PagedList / DataSource pair would be created to load data from the new state of the Database query.</p>
<p>To page in data that doesn't update, you can create a single DataSource, and pass it to a single PagedList. For example, loading from network when the network's paging API doesn't provide updates.</p>
<p>To page in data from a source that does provide updates, you can create a <code><a href="/reference/kotlin/androidx/paging/DataSource.Factory.html">DataSource.Factory</a></code>, where each DataSource created is invalidated when an update to the data set occurs that makes the current snapshot invalid. For example, when paging a query from the Database, and the table being queried inserts or removes items. You can also use a DataSource.Factory to provide multiple versions of network-paged lists. If reloading all content (e.g. in response to an action like swipe-to-refresh) is required to get a new version of data, you can connect an explicit refresh signal to call <code><a href="/reference/kotlin/androidx/paging/DataSource.html#invalidate()">invalidate</a></code> on the current <code><a href="/reference/kotlin/androidx/paging/DataSource.html">DataSource</a></code>.</p>
<p>If you have more granular update signals, such as a network API signaling an update to a single item in the list, it's recommended to load data from network into memory. Then present that data to the PagedList via a DataSource that wraps an in-memory snapshot. Each time the in-memory copy changes, invalidate the previous DataSource, and a new one wrapping the new state of the snapshot can be created.</p>
<h3> Implementing a DataSource</h3>
<p>To implement, extend one of the subclasses: <code><a href="/reference/kotlin/androidx/paging/PageKeyedDataSource.html">PageKeyedDataSource</a></code>, <code><a href="/reference/kotlin/androidx/paging/ItemKeyedDataSource.html">ItemKeyedDataSource</a></code>, or <code><a href="/reference/kotlin/androidx/paging/PositionalDataSource.html">PositionalDataSource</a></code>.</p>
<p>Use <code><a href="/reference/kotlin/androidx/paging/PageKeyedDataSource.html">PageKeyedDataSource</a></code> if pages you load embed keys for loading adjacent pages. For example a network response that returns some items, and a next/previous page links.</p>
<p>Use <code><a href="/reference/kotlin/androidx/paging/ItemKeyedDataSource.html">ItemKeyedDataSource</a></code> if you need to use data from item <code>N-1</code> to load item <code>N</code>. For example, if requesting the backend for the next comments in the list requires the ID or timestamp of the most recent loaded comment, or if querying the next users from a name-sorted database query requires the name and unique ID of the previous.</p>
<p>Use <code><a href="/reference/kotlin/androidx/paging/PositionalDataSource.html">PositionalDataSource</a></code> if you can load pages of a requested size at arbitrary positions, and provide a fixed item count. PositionalDataSource supports querying pages at arbitrary positions, so can provide data to PagedLists in arbitrary order. Note that PositionalDataSource is required to respect page size for efficient tiling. If you want to override page size (e.g. when network page size constraints are only known at runtime), use one of the other DataSource classes.</p>
<p>Because a <code>null</code> item indicates a placeholder in <code><a href="/reference/kotlin/androidx/paging/PagedList.html">PagedList</a></code>, DataSource may not return <code>null</code> items in lists that it loads. This is so that users of the PagedList can differentiate unloaded placeholder items from content that has been paged in.</p>
<div class="devsite-table-wrapper">
<table class="responsive">
<colgroup>
<col width="40%">
<col>
</colgroup>
<thead>
<tr>
<th colspan="100%">Parameters</th>
</tr>
</thead>
<tbody class="list">
<tr>
<td width="40%"><code>&lt;Key&nbsp;:&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html">Any</a>&gt;</code></td>
<td>
<p>Unique identifier for item loaded from DataSource. Often an integer to represent position in data set. Note - this is distinct from e.g. Room's <code>&lt;Value&gt;</code> Value type loaded by the DataSource.</p>
</td>
</tr>
</tbody>
</table>
</div>
<h2>Summary</h2>
<div class="devsite-table-wrapper">
<table class="responsive">
<colgroup>
<col width="40%">
<col>
</colgroup>
<thead>
<tr>
<th colspan="100%"><h3>Nested types</h3></th>
</tr>
</thead>
<tbody class="list">
<tr>
<td>
<div><code>abstract class <a href="/reference/kotlin/androidx/paging/DataSource.Factory.html">DataSource.Factory</a>&lt;Key&nbsp;:&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html">Any</a>,&nbsp;Value&nbsp;:&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html">Any</a>&gt;</code></div>
<p>Factory for DataSources.</p>
</td>
</tr>
<tr>
<td>
<div><code>fun interface <a href="/reference/kotlin/androidx/paging/DataSource.InvalidatedCallback.html">DataSource.InvalidatedCallback</a></code></div>
<p>Invalidation callback for <code><a href="/reference/kotlin/androidx/paging/DataSource.html">DataSource</a></code>.</p>
</td>
</tr>
</tbody>
</table>
</div>
<div class="devsite-table-wrapper">
<table class="responsive">
<colgroup>
<col width="40%">
<col>
</colgroup>
<thead>
<tr>
<th colspan="100%"><h3>Public functions</h3></th>
</tr>
</thead>
<tbody class="list">
<tr>
<td width="40%"><code>open <a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html">Unit</a></code></td>
<td>
<div><code>@<a href="/reference/kotlin/androidx/annotation/AnyThread.html">AnyThread</a><br><a href="/reference/kotlin/androidx/paging/DataSource.html#addInvalidatedCallback(androidx.paging.DataSource.InvalidatedCallback)">addInvalidatedCallback</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;onInvalidatedCallback:&nbsp;<a href="/reference/kotlin/androidx/paging/DataSource.InvalidatedCallback.html">DataSource.InvalidatedCallback</a><br>)</code></div>
<p>Add a callback to invoke when the DataSource is first invalidated.</p>
</td>
</tr>
<tr>
<td width="40%"><code>open <a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html">Unit</a></code></td>
<td>
<div><code>@<a href="/reference/kotlin/androidx/annotation/AnyThread.html">AnyThread</a><br><a href="/reference/kotlin/androidx/paging/DataSource.html#invalidate()">invalidate</a>()</code></div>
<p>Signal the data source to stop loading, and notify its callback.</p>
</td>
</tr>
<tr>
<td width="40%"><code>open <a href="/reference/kotlin/androidx/paging/DataSource.html">DataSource</a>&lt;Key,&nbsp;ToValue&gt;</code></td>
<td>
<div><code>&lt;ToValue&nbsp;:&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html">Any</a>&gt; <a href="/reference/kotlin/androidx/paging/DataSource.html#map(androidx.arch.core.util.Function)">map</a>(function:&nbsp;<a href="/reference/kotlin/androidx/arch/core/util/Function.html">Function</a>&lt;Value,&nbsp;ToValue&gt;)</code></div>
<p>Applies the given function to each value emitted by the DataSource.</p>
</td>
</tr>
<tr>
<td width="40%"><code>open <a href="/reference/kotlin/androidx/paging/DataSource.html">DataSource</a>&lt;Key,&nbsp;ToValue&gt;</code></td>
<td>
<div><code>&lt;ToValue&nbsp;:&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html">Any</a>&gt; <a href="/reference/kotlin/androidx/paging/DataSource.html#map(kotlin.Function1)">map</a>(function:&nbsp;(Value) <span style="white-space: nowrap;">-&gt;</span> ToValue)</code></div>
<p>Applies the given function to each value emitted by the DataSource.</p>
</td>
</tr>
<tr>
<td width="40%"><code>open <a href="/reference/kotlin/androidx/paging/DataSource.html">DataSource</a>&lt;Key,&nbsp;ToValue&gt;</code></td>
<td>
<div><code>&lt;ToValue&nbsp;:&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html">Any</a>&gt; <a href="/reference/kotlin/androidx/paging/DataSource.html#mapByPage(androidx.arch.core.util.Function)">mapByPage</a>(function:&nbsp;<a href="/reference/kotlin/androidx/arch/core/util/Function.html">Function</a>&lt;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-list/index.html">List</a>&lt;Value&gt;,&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-list/index.html">List</a>&lt;ToValue&gt;&gt;)</code></div>
<p>Applies the given function to each value emitted by the DataSource.</p>
</td>
</tr>
<tr>
<td width="40%"><code>open <a href="/reference/kotlin/androidx/paging/DataSource.html">DataSource</a>&lt;Key,&nbsp;ToValue&gt;</code></td>
<td>
<div><code>&lt;ToValue&nbsp;:&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html">Any</a>&gt; <a href="/reference/kotlin/androidx/paging/DataSource.html#mapByPage(kotlin.Function1)">mapByPage</a>(function:&nbsp;(<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-list/index.html">List</a>&lt;Value&gt;) <span style="white-space: nowrap;">-&gt;</span> <a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-list/index.html">List</a>&lt;ToValue&gt;)</code></div>
<p>Applies the given function to each value emitted by the DataSource.</p>
</td>
</tr>
<tr>
<td width="40%"><code>open <a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html">Unit</a></code></td>
<td>
<div><code>@<a href="/reference/kotlin/androidx/annotation/AnyThread.html">AnyThread</a><br><a href="/reference/kotlin/androidx/paging/DataSource.html#removeInvalidatedCallback(androidx.paging.DataSource.InvalidatedCallback)">removeInvalidatedCallback</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;onInvalidatedCallback:&nbsp;<a href="/reference/kotlin/androidx/paging/DataSource.InvalidatedCallback.html">DataSource.InvalidatedCallback</a><br>)</code></div>
<p>Remove a previously added invalidate callback.</p>
</td>
</tr>
</tbody>
</table>
</div>
<div class="devsite-table-wrapper">
<table class="responsive">
<colgroup>
<col width="40%">
<col>
</colgroup>
<thead>
<tr>
<th colspan="100%"><h3>Public properties</h3></th>
</tr>
</thead>
<tbody class="list">
<tr>
<td width="40%"><code>open <a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html">Boolean</a></code></td>
<td>
<div><code><a href="/reference/kotlin/androidx/paging/DataSource.html#isInvalid()">isInvalid</a></code></div>
</td>
</tr>
</tbody>
</table>
</div>
<div class="list">
<h2>Public functions</h2>
<div class="api-item"><a name="addInvalidatedCallback-androidx.paging.DataSource.InvalidatedCallback-"></a><a name="addinvalidatedcallback"></a>
<h3 class="api-name" id="addInvalidatedCallback(androidx.paging.DataSource.InvalidatedCallback)">addInvalidatedCallback</h3>
<pre class="api-signature no-pretty-print">@<a href="/reference/kotlin/androidx/annotation/AnyThread.html">AnyThread</a><br>open&nbsp;fun&nbsp;<a href="/reference/kotlin/androidx/paging/DataSource.html#addInvalidatedCallback(androidx.paging.DataSource.InvalidatedCallback)">addInvalidatedCallback</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;onInvalidatedCallback:&nbsp;<a href="/reference/kotlin/androidx/paging/DataSource.InvalidatedCallback.html">DataSource.InvalidatedCallback</a><br>):&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html">Unit</a></pre>
<p>Add a callback to invoke when the DataSource is first invalidated.</p>
<p>Once invalidated, a data source will not become valid again.</p>
<p>A data source will only invoke its callbacks once - the first time <code><a href="/reference/kotlin/androidx/paging/DataSource.html#invalidate()">invalidate</a></code> is called, on that thread.</p>
<p>If this <code><a href="/reference/kotlin/androidx/paging/DataSource.html">DataSource</a></code> is already invalid, the provided <code><a href="/reference/kotlin/androidx/paging/DataSource.html#addInvalidatedCallback(androidx.paging.DataSource.InvalidatedCallback)">onInvalidatedCallback</a></code> will be triggered immediately.</p>
<div class="devsite-table-wrapper">
<table class="responsive">
<colgroup>
<col width="40%">
<col>
</colgroup>
<thead>
<tr>
<th colspan="100%">Parameters</th>
</tr>
</thead>
<tbody class="list">
<tr>
<td width="40%"><code>onInvalidatedCallback:&nbsp;<a href="/reference/kotlin/androidx/paging/DataSource.InvalidatedCallback.html">DataSource.InvalidatedCallback</a></code></td>
<td>
<p>The callback, will be invoked on thread that invalidates the <code><a href="/reference/kotlin/androidx/paging/DataSource.html">DataSource</a></code>.</p>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="api-item"><a name="invalidate--"></a><a name="invalidate"></a>
<h3 class="api-name" id="invalidate()">invalidate</h3>
<pre class="api-signature no-pretty-print">@<a href="/reference/kotlin/androidx/annotation/AnyThread.html">AnyThread</a><br>open&nbsp;fun&nbsp;<a href="/reference/kotlin/androidx/paging/DataSource.html#invalidate()">invalidate</a>():&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html">Unit</a></pre>
<p>Signal the data source to stop loading, and notify its callback.</p>
<p>If invalidate has already been called, this method does nothing.</p>
</div>
<div class="api-item"><a name="map-androidx.arch.core.util.Function-"></a><a name="map"></a>
<h3 class="api-name" id="map(androidx.arch.core.util.Function)">map</h3>
<pre class="api-signature no-pretty-print">open&nbsp;fun&nbsp;&lt;ToValue&nbsp;:&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html">Any</a>&gt; <a href="/reference/kotlin/androidx/paging/DataSource.html#map(androidx.arch.core.util.Function)">map</a>(function:&nbsp;<a href="/reference/kotlin/androidx/arch/core/util/Function.html">Function</a>&lt;Value,&nbsp;ToValue&gt;):&nbsp;<a href="/reference/kotlin/androidx/paging/DataSource.html">DataSource</a>&lt;Key,&nbsp;ToValue&gt;</pre>
<p>Applies the given function to each value emitted by the DataSource.</p>
<p>Same as <code><a href="/reference/kotlin/androidx/paging/DataSource.html#mapByPage(androidx.arch.core.util.Function)">mapByPage</a></code>, but operates on individual items.</p>
<div class="devsite-table-wrapper">
<table class="responsive">
<colgroup>
<col width="40%">
<col>
</colgroup>
<thead>
<tr>
<th colspan="100%">Parameters</th>
</tr>
</thead>
<tbody class="list">
<tr>
<td width="40%"><code>&lt;ToValue&nbsp;:&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html">Any</a>&gt;</code></td>
<td>
<p>Type of items produced by the new DataSource, from the passed function.</p>
</td>
</tr>
<tr>
<td width="40%"><code>function:&nbsp;<a href="/reference/kotlin/androidx/arch/core/util/Function.html">Function</a>&lt;Value,&nbsp;ToValue&gt;</code></td>
<td>
<p>Function that runs on each loaded item, returning items of a potentially new type.</p>
</td>
</tr>
</tbody>
</table>
</div>
<div class="devsite-table-wrapper">
<table class="responsive">
<colgroup>
<col width="40%">
<col>
</colgroup>
<thead>
<tr>
<th colspan="100%">Returns</th>
</tr>
</thead>
<tbody class="list">
<tr>
<td width="40%"><code><a href="/reference/kotlin/androidx/paging/DataSource.html">DataSource</a>&lt;Key,&nbsp;ToValue&gt;</code></td>
<td>
<p>A new DataSource, which transforms items using the given function.</p>
</td>
</tr>
</tbody>
</table>
</div>
<div class="devsite-table-wrapper">
<table class="responsive">
<colgroup>
<col width="40%">
<col>
</colgroup>
<thead>
<tr>
<th colspan="100%">See also</th>
</tr>
</thead>
<tbody class="list">
<tr>
<td width="40%"><code><a href="/reference/kotlin/androidx/paging/DataSource.html#mapByPage(androidx.arch.core.util.Function)">mapByPage</a></code></td>
<td></td>
</tr>
<tr>
<td width="40%"><code><a href="/reference/kotlin/androidx/paging/DataSource.Factory.html#map(androidx.arch.core.util.Function)">map</a></code></td>
<td></td>
</tr>
<tr>
<td width="40%"><code><a href="/reference/kotlin/androidx/paging/DataSource.Factory.html#mapByPage(androidx.arch.core.util.Function)">mapByPage</a></code></td>
<td></td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="api-item"><a name="map-kotlin.Function1-"></a><a name="map"></a>
<h3 class="api-name" id="map(kotlin.Function1)">map</h3>
<pre class="api-signature no-pretty-print">open&nbsp;fun&nbsp;&lt;ToValue&nbsp;:&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html">Any</a>&gt; <a href="/reference/kotlin/androidx/paging/DataSource.html#map(kotlin.Function1)">map</a>(function:&nbsp;(Value) <span style="white-space: nowrap;">-&gt;</span> ToValue):&nbsp;<a href="/reference/kotlin/androidx/paging/DataSource.html">DataSource</a>&lt;Key,&nbsp;ToValue&gt;</pre>
<p>Applies the given function to each value emitted by the DataSource.</p>
<p>An overload of <code><a href="/reference/kotlin/androidx/paging/DataSource.html#map(androidx.arch.core.util.Function)">map</a></code> that accepts a kotlin function type.</p>
<p>Same as <code><a href="/reference/kotlin/androidx/paging/DataSource.html#mapByPage(androidx.arch.core.util.Function)">mapByPage</a></code>, but operates on individual items.</p>
<div class="devsite-table-wrapper">
<table class="responsive">
<colgroup>
<col width="40%">
<col>
</colgroup>
<thead>
<tr>
<th colspan="100%">Parameters</th>
</tr>
</thead>
<tbody class="list">
<tr>
<td width="40%"><code>&lt;ToValue&nbsp;:&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html">Any</a>&gt;</code></td>
<td>
<p>Type of items produced by the new DataSource, from the passed function.</p>
</td>
</tr>
<tr>
<td width="40%"><code>function:&nbsp;(Value) <span style="white-space: nowrap;">-&gt;</span> ToValue</code></td>
<td>
<p>Function that runs on each loaded item, returning items of a potentially new type.</p>
</td>
</tr>
</tbody>
</table>
</div>
<div class="devsite-table-wrapper">
<table class="responsive">
<colgroup>
<col width="40%">
<col>
</colgroup>
<thead>
<tr>
<th colspan="100%">Returns</th>
</tr>
</thead>
<tbody class="list">
<tr>
<td width="40%"><code><a href="/reference/kotlin/androidx/paging/DataSource.html">DataSource</a>&lt;Key,&nbsp;ToValue&gt;</code></td>
<td>
<p>A new DataSource, which transforms items using the given function.</p>
</td>
</tr>
</tbody>
</table>
</div>
<div class="devsite-table-wrapper">
<table class="responsive">
<colgroup>
<col width="40%">
<col>
</colgroup>
<thead>
<tr>
<th colspan="100%">See also</th>
</tr>
</thead>
<tbody class="list">
<tr>
<td width="40%"><code><a href="/reference/kotlin/androidx/paging/DataSource.html#mapByPage(androidx.arch.core.util.Function)">mapByPage</a></code></td>
<td></td>
</tr>
<tr>
<td width="40%"><code><a href="/reference/kotlin/androidx/paging/DataSource.Factory.html#map(androidx.arch.core.util.Function)">map</a></code></td>
<td></td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="api-item"><a name="mapByPage-androidx.arch.core.util.Function-"></a><a name="mapbypage"></a>
<h3 class="api-name" id="mapByPage(androidx.arch.core.util.Function)">mapByPage</h3>
<pre class="api-signature no-pretty-print">open&nbsp;fun&nbsp;&lt;ToValue&nbsp;:&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html">Any</a>&gt; <a href="/reference/kotlin/androidx/paging/DataSource.html#mapByPage(androidx.arch.core.util.Function)">mapByPage</a>(function:&nbsp;<a href="/reference/kotlin/androidx/arch/core/util/Function.html">Function</a>&lt;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-list/index.html">List</a>&lt;Value&gt;,&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-list/index.html">List</a>&lt;ToValue&gt;&gt;):&nbsp;<a href="/reference/kotlin/androidx/paging/DataSource.html">DataSource</a>&lt;Key,&nbsp;ToValue&gt;</pre>
<p>Applies the given function to each value emitted by the DataSource.</p>
<p>Same as <code><a href="/reference/kotlin/androidx/paging/DataSource.html#map(androidx.arch.core.util.Function)">map</a></code>, but allows for batch conversions.</p>
<div class="devsite-table-wrapper">
<table class="responsive">
<colgroup>
<col width="40%">
<col>
</colgroup>
<thead>
<tr>
<th colspan="100%">Parameters</th>
</tr>
</thead>
<tbody class="list">
<tr>
<td width="40%"><code>&lt;ToValue&nbsp;:&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html">Any</a>&gt;</code></td>
<td>
<p>Type of items produced by the new DataSource, from the passed function.</p>
</td>
</tr>
<tr>
<td width="40%"><code>function:&nbsp;<a href="/reference/kotlin/androidx/arch/core/util/Function.html">Function</a>&lt;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-list/index.html">List</a>&lt;Value&gt;,&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-list/index.html">List</a>&lt;ToValue&gt;&gt;</code></td>
<td>
<p>Function that runs on each loaded page, returning items of a potentially new type.</p>
</td>
</tr>
</tbody>
</table>
</div>
<div class="devsite-table-wrapper">
<table class="responsive">
<colgroup>
<col width="40%">
<col>
</colgroup>
<thead>
<tr>
<th colspan="100%">Returns</th>
</tr>
</thead>
<tbody class="list">
<tr>
<td width="40%"><code><a href="/reference/kotlin/androidx/paging/DataSource.html">DataSource</a>&lt;Key,&nbsp;ToValue&gt;</code></td>
<td>
<p>A new DataSource, which transforms items using the given function.</p>
</td>
</tr>
</tbody>
</table>
</div>
<div class="devsite-table-wrapper">
<table class="responsive">
<colgroup>
<col width="40%">
<col>
</colgroup>
<thead>
<tr>
<th colspan="100%">See also</th>
</tr>
</thead>
<tbody class="list">
<tr>
<td width="40%"><code><a href="/reference/kotlin/androidx/paging/DataSource.html#map(androidx.arch.core.util.Function)">map</a></code></td>
<td></td>
</tr>
<tr>
<td width="40%"><code><a href="/reference/kotlin/androidx/paging/DataSource.Factory.html#map(androidx.arch.core.util.Function)">map</a></code></td>
<td></td>
</tr>
<tr>
<td width="40%"><code><a href="/reference/kotlin/androidx/paging/DataSource.Factory.html#mapByPage(androidx.arch.core.util.Function)">mapByPage</a></code></td>
<td></td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="api-item"><a name="mapByPage-kotlin.Function1-"></a><a name="mapbypage"></a>
<h3 class="api-name" id="mapByPage(kotlin.Function1)">mapByPage</h3>
<pre class="api-signature no-pretty-print">open&nbsp;fun&nbsp;&lt;ToValue&nbsp;:&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html">Any</a>&gt; <a href="/reference/kotlin/androidx/paging/DataSource.html#mapByPage(kotlin.Function1)">mapByPage</a>(function:&nbsp;(<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-list/index.html">List</a>&lt;Value&gt;) <span style="white-space: nowrap;">-&gt;</span> <a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-list/index.html">List</a>&lt;ToValue&gt;):&nbsp;<a href="/reference/kotlin/androidx/paging/DataSource.html">DataSource</a>&lt;Key,&nbsp;ToValue&gt;</pre>
<p>Applies the given function to each value emitted by the DataSource.</p>
<p>An overload of <code><a href="/reference/kotlin/androidx/paging/DataSource.html#mapByPage(androidx.arch.core.util.Function)">mapByPage</a></code> that accepts a kotlin function type.</p>
<p>Same as <code><a href="/reference/kotlin/androidx/paging/DataSource.html#map(androidx.arch.core.util.Function)">map</a></code>, but allows for batch conversions.</p>
<div class="devsite-table-wrapper">
<table class="responsive">
<colgroup>
<col width="40%">
<col>
</colgroup>
<thead>
<tr>
<th colspan="100%">Parameters</th>
</tr>
</thead>
<tbody class="list">
<tr>
<td width="40%"><code>&lt;ToValue&nbsp;:&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html">Any</a>&gt;</code></td>
<td>
<p>Type of items produced by the new DataSource, from the passed function.</p>
</td>
</tr>
<tr>
<td width="40%"><code>function:&nbsp;(<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-list/index.html">List</a>&lt;Value&gt;) <span style="white-space: nowrap;">-&gt;</span> <a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-list/index.html">List</a>&lt;ToValue&gt;</code></td>
<td>
<p>Function that runs on each loaded page, returning items of a potentially new type.</p>
</td>
</tr>
</tbody>
</table>
</div>
<div class="devsite-table-wrapper">
<table class="responsive">
<colgroup>
<col width="40%">
<col>
</colgroup>
<thead>
<tr>
<th colspan="100%">Returns</th>
</tr>
</thead>
<tbody class="list">
<tr>
<td width="40%"><code><a href="/reference/kotlin/androidx/paging/DataSource.html">DataSource</a>&lt;Key,&nbsp;ToValue&gt;</code></td>
<td>
<p>A new <code><a href="/reference/kotlin/androidx/paging/DataSource.html">DataSource</a></code>, which transforms items using the given function.</p>
</td>
</tr>
</tbody>
</table>
</div>
<div class="devsite-table-wrapper">
<table class="responsive">
<colgroup>
<col width="40%">
<col>
</colgroup>
<thead>
<tr>
<th colspan="100%">See also</th>
</tr>
</thead>
<tbody class="list">
<tr>
<td width="40%"><code><a href="/reference/kotlin/androidx/paging/DataSource.html#map(androidx.arch.core.util.Function)">map</a></code></td>
<td></td>
</tr>
<tr>
<td width="40%"><code><a href="/reference/kotlin/androidx/paging/DataSource.Factory.html#map(androidx.arch.core.util.Function)">map</a></code></td>
<td></td>
</tr>
<tr>
<td width="40%"><code><a href="/reference/kotlin/androidx/paging/DataSource.Factory.html#mapByPage(androidx.arch.core.util.Function)">mapByPage</a></code></td>
<td></td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="api-item"><a name="removeInvalidatedCallback-androidx.paging.DataSource.InvalidatedCallback-"></a><a name="removeinvalidatedcallback"></a>
<h3 class="api-name" id="removeInvalidatedCallback(androidx.paging.DataSource.InvalidatedCallback)">removeInvalidatedCallback</h3>
<pre class="api-signature no-pretty-print">@<a href="/reference/kotlin/androidx/annotation/AnyThread.html">AnyThread</a><br>open&nbsp;fun&nbsp;<a href="/reference/kotlin/androidx/paging/DataSource.html#removeInvalidatedCallback(androidx.paging.DataSource.InvalidatedCallback)">removeInvalidatedCallback</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;onInvalidatedCallback:&nbsp;<a href="/reference/kotlin/androidx/paging/DataSource.InvalidatedCallback.html">DataSource.InvalidatedCallback</a><br>):&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html">Unit</a></pre>
<p>Remove a previously added invalidate callback.</p>
<div class="devsite-table-wrapper">
<table class="responsive">
<colgroup>
<col width="40%">
<col>
</colgroup>
<thead>
<tr>
<th colspan="100%">Parameters</th>
</tr>
</thead>
<tbody class="list">
<tr>
<td width="40%"><code>onInvalidatedCallback:&nbsp;<a href="/reference/kotlin/androidx/paging/DataSource.InvalidatedCallback.html">DataSource.InvalidatedCallback</a></code></td>
<td>
<p>The previously added callback.</p>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<div class="list">
<h2>Public properties</h2>
<div class="api-item"><a name="getIsInvalid()"></a><a name="setIsInvalid()"></a><a name="getIsInvalid--"></a><a name="setIsInvalid--"></a>
<h3 class="api-name" id="isInvalid()">isInvalid</h3>
<pre class="api-signature no-pretty-print">open&nbsp;val&nbsp;<a href="/reference/kotlin/androidx/paging/DataSource.html#isInvalid()">isInvalid</a>:&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html">Boolean</a></pre>
<div class="devsite-table-wrapper">
<table class="responsive">
<colgroup>
<col width="40%">
<col>
</colgroup>
<thead>
<tr>
<th colspan="100%">Returns</th>
</tr>
</thead>
<tbody class="list">
<tr>
<td width="40%"><code><a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html">Boolean</a></code></td>
<td>
<p><code>true</code> if the data source is invalid, and can no longer be queried for data.</p>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</body>
</html>