blob: 24f982974a857a0c574e2d289f97325b1356f530 [file] [log] [blame]
<html devsite="true">
<head>
<title>ItemKeyedDataSource</title>
{% setvar book_path %}/reference/kotlin/androidx/_book.yaml{% endsetvar %}
{% include "_shared/_reference-head-tags.html" %}
</head>
<body>
<h1>ItemKeyedDataSource</h1>
{% setvar page_path %}androidx/paging/ItemKeyedDataSource.html{% endsetvar %}
{% setvar can_switch %}1{% endsetvar %}
{% include "reference/_kotlin_switcher2.md" %}
<p>
<pre>abstract class ItemKeyedDataSource&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; : <a href="/reference/kotlin/androidx/paging/DataSource.html">DataSource</a></pre>
</p>
<div class="devsite-table-wrapper">
<table class="jd-inheritance-table">
<tbody>
<tr>
<td colspan="3"><a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html">Any</a></td>
</tr>
<tr>
<td class="jd-inheritance-space">&nbsp;&nbsp;&nbsp;↳</td>
<td colspan="2"><a href="/reference/kotlin/androidx/paging/DataSource.html">DataSource</a></td>
</tr>
<tr>
<td>&nbsp;</td>
<td class="jd-inheritance-space">&nbsp;&nbsp;&nbsp;↳</td>
<td colspan="1"><a href="/reference/kotlin/androidx/paging/ItemKeyedDataSource.html">ItemKeyedDataSource</a></td>
</tr>
</tbody>
</table>
</div>
<hr>
<aside class="caution"><strong>This class is deprecated.</strong><br>ItemKeyedDataSource is deprecated and has been replaced by PagingSource</aside>
<p>Incremental data loader for paging keyed content, where loaded content uses previously loaded items as input to future loads.</p>
<p>Implement a DataSource using ItemKeyedDataSource if you need to use data from item <code>N - 1</code> to load item <code>N</code>. This is common, for example, in uniquely sorted database queries where attributes of the item such just before the next query define how to execute it.</p>
<p>The <code>InMemoryByItemRepository</code> in the <a href="https://github.com/googlesamples/android-architecture-components/blob/master/PagingWithNetworkSample/README.md">PagingWithNetworkSample</a> shows how to implement a network ItemKeyedDataSource using <a href="https://square.github.io/retrofit/">Retrofit</a>, while handling swipe-to-refresh, network errors, and retry.</p>
<div class="devsite-table-wrapper">
<table class="responsive">
<thead>
<tr>
<th colspan="2">Parameters</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>&lt;Key&nbsp;:&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html">Any</a>&gt;</code></td>
<td width="100%">
<p>Type of data used to query Value types out of the <code><a href="/reference/kotlin/androidx/paging/DataSource.html">DataSource</a></code>.</p>
</td>
</tr>
<tr>
<td><code>&lt;Value&nbsp;:&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html">Any</a>&gt;</code></td>
<td width="100%">
<p>Type of items being loaded by the <code><a href="/reference/kotlin/androidx/paging/DataSource.html">DataSource</a></code>.</p>
</td>
</tr>
</tbody>
</table>
</div>
<h2>Summary</h2>
<div class="devsite-table-wrapper">
<table class="responsive">
<thead>
<tr>
<th colspan="2"><h3>Nested types</h3></th>
</tr>
</thead>
<tbody>
<tr>
<td><code><a href="/reference/kotlin/androidx/paging/ItemKeyedDataSource.LoadCallback.html">ItemKeyedDataSource.LoadCallback</a></code></td>
<td width="100%">
<p>Callback for ItemKeyedDataSource <code><a href="/reference/kotlin/androidx/paging/ItemKeyedDataSource.html#loadBefore(androidx.paging.ItemKeyedDataSource.LoadParams)">loadBefore</a></code> and <code><a href="/reference/kotlin/androidx/paging/ItemKeyedDataSource.html#loadAfter(androidx.paging.ItemKeyedDataSource.LoadParams)">loadAfter</a></code> to return data.</p>
</td>
</tr>
<tr>
<td><code><a href="/reference/kotlin/androidx/paging/ItemKeyedDataSource.LoadInitialCallback.html">ItemKeyedDataSource.LoadInitialCallback</a></code></td>
<td width="100%">
<p>Callback for <code><a href="/reference/kotlin/androidx/paging/ItemKeyedDataSource.html#loadInitial(androidx.paging.ItemKeyedDataSource.LoadInitialParams)">loadInitial</a></code> to return data and, optionally, position/count information.</p>
</td>
</tr>
<tr>
<td><code><a href="/reference/kotlin/androidx/paging/ItemKeyedDataSource.LoadInitialParams.html">ItemKeyedDataSource.LoadInitialParams</a></code></td>
<td width="100%">
<p>Holder object for inputs to <code><a href="/reference/kotlin/androidx/paging/ItemKeyedDataSource.html#loadInitial(androidx.paging.ItemKeyedDataSource.LoadInitialParams)">loadInitial</a></code>.</p>
</td>
</tr>
<tr>
<td><code><a href="/reference/kotlin/androidx/paging/ItemKeyedDataSource.LoadParams.html">ItemKeyedDataSource.LoadParams</a></code></td>
<td width="100%">
<p>Holder object for inputs to <code><a href="/reference/kotlin/androidx/paging/ItemKeyedDataSource.html#loadBefore(androidx.paging.ItemKeyedDataSource.LoadParams)">loadBefore</a></code> and <code><a href="/reference/kotlin/androidx/paging/ItemKeyedDataSource.html#loadAfter(androidx.paging.ItemKeyedDataSource.LoadParams)">loadAfter</a></code>.</p>
</td>
</tr>
</tbody>
</table>
</div>
<div class="devsite-table-wrapper">
<table class="responsive">
<thead>
<tr>
<th colspan="2"><h3>Public properties</h3></th>
</tr>
</thead>
<tbody>
<tr>
<td><code>open <a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html">Boolean</a></code></td>
<td width="100%">
<div><code><a href="/reference/kotlin/androidx/paging/ItemKeyedDataSource.html#isInvalid()">isInvalid</a></code></div>
</td>
</tr>
</tbody>
</table>
</div>
<div class="devsite-table-wrapper">
<table class="responsive">
<thead>
<tr>
<th colspan="2"><h3>Public constructors</h3></th>
</tr>
</thead>
<tbody>
<tr>
<td>
<div><code>&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; <a href="/reference/kotlin/androidx/paging/ItemKeyedDataSource.html#ItemKeyedDataSource()">ItemKeyedDataSource</a>()</code></div>
</td>
</tr>
</tbody>
</table>
</div>
<div class="devsite-table-wrapper">
<table class="responsive">
<thead>
<tr>
<th colspan="2"><h3>Public functions</h3></th>
</tr>
</thead>
<tbody>
<tr>
<td><code>abstract Key</code></td>
<td width="100%">
<div><code><a href="/reference/kotlin/androidx/paging/ItemKeyedDataSource.html#getKey(kotlin.Any)">getKey</a>(item:&nbsp;Value)</code></div>
<p>Return a key associated with the given item.</p>
</td>
</tr>
<tr>
<td><code>abstract <a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html">Unit</a></code></td>
<td width="100%">
<div><code><a href="/reference/kotlin/androidx/paging/ItemKeyedDataSource.html#loadAfter(androidx.paging.ItemKeyedDataSource.LoadParams,androidx.paging.ItemKeyedDataSource.LoadCallback)">loadAfter</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;params:&nbsp;<a href="/reference/kotlin/androidx/paging/ItemKeyedDataSource.LoadParams.html">ItemKeyedDataSource.LoadParams</a>&lt;Key&gt;,<br>&nbsp;&nbsp;&nbsp;&nbsp;callback:&nbsp;<a href="/reference/kotlin/androidx/paging/ItemKeyedDataSource.LoadCallback.html">ItemKeyedDataSource.LoadCallback</a>&lt;Value&gt;<br>)</code></div>
<p>Load list data after the key specified in <code><a href="/reference/kotlin/androidx/paging/ItemKeyedDataSource.LoadParams.html#key()">LoadParams.key</a></code>.</p>
</td>
</tr>
<tr>
<td><code>abstract <a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html">Unit</a></code></td>
<td width="100%">
<div><code><a href="/reference/kotlin/androidx/paging/ItemKeyedDataSource.html#loadBefore(androidx.paging.ItemKeyedDataSource.LoadParams,androidx.paging.ItemKeyedDataSource.LoadCallback)">loadBefore</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;params:&nbsp;<a href="/reference/kotlin/androidx/paging/ItemKeyedDataSource.LoadParams.html">ItemKeyedDataSource.LoadParams</a>&lt;Key&gt;,<br>&nbsp;&nbsp;&nbsp;&nbsp;callback:&nbsp;<a href="/reference/kotlin/androidx/paging/ItemKeyedDataSource.LoadCallback.html">ItemKeyedDataSource.LoadCallback</a>&lt;Value&gt;<br>)</code></div>
<p>Load list data before the key specified in <code><a href="/reference/kotlin/androidx/paging/ItemKeyedDataSource.LoadParams.html#key()">LoadParams.key</a></code>.</p>
</td>
</tr>
<tr>
<td><code>abstract <a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html">Unit</a></code></td>
<td width="100%">
<div><code><a href="/reference/kotlin/androidx/paging/ItemKeyedDataSource.html#loadInitial(androidx.paging.ItemKeyedDataSource.LoadInitialParams,androidx.paging.ItemKeyedDataSource.LoadInitialCallback)">loadInitial</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;params:&nbsp;<a href="/reference/kotlin/androidx/paging/ItemKeyedDataSource.LoadInitialParams.html">ItemKeyedDataSource.LoadInitialParams</a>&lt;Key&gt;,<br>&nbsp;&nbsp;&nbsp;&nbsp;callback:&nbsp;<a href="/reference/kotlin/androidx/paging/ItemKeyedDataSource.LoadInitialCallback.html">ItemKeyedDataSource.LoadInitialCallback</a>&lt;Value&gt;<br>)</code></div>
<p>Load initial data.</p>
</td>
</tr>
<tr>
<td><code>final <a href="/reference/kotlin/androidx/paging/ItemKeyedDataSource.html">ItemKeyedDataSource</a>&lt;Key,&nbsp;ToValue&gt;</code></td>
<td width="100%">
<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/ItemKeyedDataSource.html#map()">map</a>(function:&nbsp;<a href="/reference/kotlin/[JVM root]/&lt;ERROR CLASS&gt;.html">&lt;ERROR CLASS&gt;</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><code>final <a href="/reference/kotlin/androidx/paging/ItemKeyedDataSource.html">ItemKeyedDataSource</a>&lt;Key,&nbsp;ToValue&gt;</code></td>
<td width="100%">
<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/ItemKeyedDataSource.html#map(kotlin.Function1)">map</a>(function:&nbsp;(Value)&nbsp;-&gt;&nbsp;ToValue)</code></div>
<p>Applies the given function to each value emitted by the DataSource.</p>
</td>
</tr>
<tr>
<td><code>final <a href="/reference/kotlin/androidx/paging/ItemKeyedDataSource.html">ItemKeyedDataSource</a>&lt;Key,&nbsp;ToValue&gt;</code></td>
<td width="100%">
<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/ItemKeyedDataSource.html#mapByPage()">mapByPage</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;function:&nbsp;<a href="/reference/kotlin/[JVM root]/&lt;ERROR CLASS&gt;.html">&lt;ERROR CLASS&gt;</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;<br>)</code></div>
<p>Applies the given function to each value emitted by the DataSource.</p>
</td>
</tr>
<tr>
<td><code>final <a href="/reference/kotlin/androidx/paging/ItemKeyedDataSource.html">ItemKeyedDataSource</a>&lt;Key,&nbsp;ToValue&gt;</code></td>
<td width="100%">
<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/ItemKeyedDataSource.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;)&nbsp;-&gt;&nbsp;<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>
</tbody>
</table>
</div>
<div class="devsite-table-wrapper">
<table class="responsive" id="inhmethods">
<thead>
<tr>
<th colspan="2"><h3>Inherited functions</h3></th>
</tr>
</thead>
<tbody>
<tr>
<td><devsite-expandable><span class="expand-control">From class <a href="/reference/kotlin/androidx/paging/DataSource.html">DataSource</a></span>
<div class="devsite-table-wrapper">
<table class="responsive">
<tbody>
<tr>
<td><code>open @<a href="/reference/kotlin/[JVM root]/&lt;ERROR CLASS&gt;.html">&lt;ERROR CLASS&gt;</a>&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html">Unit</a></code></td>
<td width="100%">
<div><code><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><code>open @<a href="/reference/kotlin/[JVM root]/&lt;ERROR CLASS&gt;.html">&lt;ERROR CLASS&gt;</a>&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html">Unit</a></code></td>
<td width="100%">
<div><code><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><code>open @<a href="/reference/kotlin/[JVM root]/&lt;ERROR CLASS&gt;.html">&lt;ERROR CLASS&gt;</a>&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html">Unit</a></code></td>
<td width="100%">
<div><code><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>
</devsite-expandable> </td>
</tr>
</tbody>
</table>
</div>
<h2>Public properties</h2>
<div><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/ItemKeyedDataSource.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">
<thead>
<tr>
<th colspan="2">Returns</th>
</tr>
</thead>
<tbody>
<tr>
<td><code><a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html">Boolean</a></code></td>
<td width="100%">
<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>
<h2>Public constructors</h2>
<div><a name="ItemKeyedDataSource--"></a>
<h3 class="api-name" id="ItemKeyedDataSource()">ItemKeyedDataSource</h3>
<pre class="api-signature no-pretty-print">&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; <a href="/reference/kotlin/androidx/paging/ItemKeyedDataSource.html#ItemKeyedDataSource()">ItemKeyedDataSource</a>()</pre>
<div class="devsite-table-wrapper">
<table class="responsive">
<thead>
<tr>
<th colspan="2">Parameters</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>&lt;Key&nbsp;:&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html">Any</a>&gt;</code></td>
<td width="100%">
<p>Type of data used to query Value types out of the <code><a href="/reference/kotlin/androidx/paging/DataSource.html">DataSource</a></code>.</p>
</td>
</tr>
<tr>
<td><code>&lt;Value&nbsp;:&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html">Any</a>&gt;</code></td>
<td width="100%">
<p>Type of items being loaded by the <code><a href="/reference/kotlin/androidx/paging/DataSource.html">DataSource</a></code>.</p>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<h2>Public functions</h2>
<div><a name="getKey-kotlin.Any-"></a>
<h3 class="api-name" id="getKey(kotlin.Any)">getKey</h3>
<pre class="api-signature no-pretty-print">abstract&nbsp;fun&nbsp;<a href="/reference/kotlin/androidx/paging/ItemKeyedDataSource.html#getKey(kotlin.Any)">getKey</a>(item:&nbsp;Value):&nbsp;Key</pre>
<p>Return a key associated with the given item.</p>
<p>If your ItemKeyedDataSource is loading from a source that is sorted and loaded by a unique integer ID, you would return <code>item.getID()</code> here. This key can then be passed to <code><a href="/reference/kotlin/androidx/paging/ItemKeyedDataSource.html#loadBefore(androidx.paging.ItemKeyedDataSource.LoadParams)">loadBefore</a></code> or <code><a href="/reference/kotlin/androidx/paging/ItemKeyedDataSource.html#loadAfter(androidx.paging.ItemKeyedDataSource.LoadParams)">loadAfter</a></code> to load additional items adjacent to the item passed to this function.</p>
<p>If your key is more complex, such as when you're sorting by name, then resolving collisions with integer ID, you'll need to return both. In such a case you would use a wrapper class, such as <code>Pair&lt;String, Integer&gt;</code> or, in Kotlin, <code>data class Key(val name: String, val id: Int)</code></p>
<div class="devsite-table-wrapper">
<table class="responsive">
<thead>
<tr>
<th colspan="2">Returns</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>Key</code></td>
<td width="100%">
<p>Key associated with given item.</p>
</td>
</tr>
</tbody>
</table>
</div>
<div class="devsite-table-wrapper">
<table class="responsive">
<thead>
<tr>
<th colspan="2">Parameters</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>item:&nbsp;Value</code></td>
<td width="100%">
<p>Item to get the key from.</p>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<div><a name="loadAfter(androidx.paging.ItemKeyedDataSource.LoadParams, androidx.paging.ItemKeyedDataSource.LoadCallback)"></a><a name="loadAfter-androidx.paging.ItemKeyedDataSource.LoadParams-androidx.paging.ItemKeyedDataSource.LoadCallback-"></a>
<h3 class="api-name" id="loadAfter(androidx.paging.ItemKeyedDataSource.LoadParams,androidx.paging.ItemKeyedDataSource.LoadCallback)">loadAfter</h3>
<pre class="api-signature no-pretty-print">abstract&nbsp;fun&nbsp;<a href="/reference/kotlin/androidx/paging/ItemKeyedDataSource.html#loadAfter(androidx.paging.ItemKeyedDataSource.LoadParams,androidx.paging.ItemKeyedDataSource.LoadCallback)">loadAfter</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;params:&nbsp;<a href="/reference/kotlin/androidx/paging/ItemKeyedDataSource.LoadParams.html">ItemKeyedDataSource.LoadParams</a>&lt;Key&gt;,<br>&nbsp;&nbsp;&nbsp;&nbsp;callback:&nbsp;<a href="/reference/kotlin/androidx/paging/ItemKeyedDataSource.LoadCallback.html">ItemKeyedDataSource.LoadCallback</a>&lt;Value&gt;<br>):&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html">Unit</a></pre>
<p>Load list data after the key specified in <code><a href="/reference/kotlin/androidx/paging/ItemKeyedDataSource.LoadParams.html#key()">LoadParams.key</a></code>.</p>
<p>It's valid to return a different list size than the page size if it's easier, e.g. if your backend defines page sizes. It is generally preferred to increase the number loaded than reduce.</p>
<p>Data may be passed synchronously during the loadAfter method, or deferred and called at a later time. Further loads going down will be blocked until the callback is called.</p>
<p>If data cannot be loaded (for example, if the request is invalid, or the data would be stale and inconsistent), it is valid to call <code><a href="/reference/kotlin/androidx/paging/ItemKeyedDataSource.html#invalidate()">invalidate</a></code> to invalidate the data source, and prevent further loading.</p>
<div class="devsite-table-wrapper">
<table class="responsive">
<thead>
<tr>
<th colspan="2">Parameters</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>params:&nbsp;<a href="/reference/kotlin/androidx/paging/ItemKeyedDataSource.LoadParams.html">ItemKeyedDataSource.LoadParams</a>&lt;Key&gt;</code></td>
<td width="100%">
<p>Parameters for the load, including the key to load after, and requested size.</p>
</td>
</tr>
<tr>
<td><code>callback:&nbsp;<a href="/reference/kotlin/androidx/paging/ItemKeyedDataSource.LoadCallback.html">ItemKeyedDataSource.LoadCallback</a>&lt;Value&gt;</code></td>
<td width="100%">
<p>Callback that receives loaded data.</p>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<div><a name="loadBefore(androidx.paging.ItemKeyedDataSource.LoadParams, androidx.paging.ItemKeyedDataSource.LoadCallback)"></a><a name="loadBefore-androidx.paging.ItemKeyedDataSource.LoadParams-androidx.paging.ItemKeyedDataSource.LoadCallback-"></a>
<h3 class="api-name" id="loadBefore(androidx.paging.ItemKeyedDataSource.LoadParams,androidx.paging.ItemKeyedDataSource.LoadCallback)">loadBefore</h3>
<pre class="api-signature no-pretty-print">abstract&nbsp;fun&nbsp;<a href="/reference/kotlin/androidx/paging/ItemKeyedDataSource.html#loadBefore(androidx.paging.ItemKeyedDataSource.LoadParams,androidx.paging.ItemKeyedDataSource.LoadCallback)">loadBefore</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;params:&nbsp;<a href="/reference/kotlin/androidx/paging/ItemKeyedDataSource.LoadParams.html">ItemKeyedDataSource.LoadParams</a>&lt;Key&gt;,<br>&nbsp;&nbsp;&nbsp;&nbsp;callback:&nbsp;<a href="/reference/kotlin/androidx/paging/ItemKeyedDataSource.LoadCallback.html">ItemKeyedDataSource.LoadCallback</a>&lt;Value&gt;<br>):&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html">Unit</a></pre>
<p>Load list data before the key specified in <code><a href="/reference/kotlin/androidx/paging/ItemKeyedDataSource.LoadParams.html#key()">LoadParams.key</a></code>.</p>
<p>It's valid to return a different list size than the page size if it's easier, e.g. if your backend defines page sizes. It is generally preferred to increase the number loaded than reduce.</p>
<p><b>Note:</b> Data returned will be prepended just before the key passed, so if you vary size, ensure that the last item is adjacent to the passed key.</p>
<p>Data may be passed synchronously during the loadBefore method, or deferred and called at a later time. Further loads going up will be blocked until the callback is called.</p>
<p>If data cannot be loaded (for example, if the request is invalid, or the data would be stale and inconsistent), it is valid to call <code><a href="/reference/kotlin/androidx/paging/ItemKeyedDataSource.html#invalidate()">invalidate</a></code> to invalidate the data source, and prevent further loading.</p>
<div class="devsite-table-wrapper">
<table class="responsive">
<thead>
<tr>
<th colspan="2">Parameters</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>params:&nbsp;<a href="/reference/kotlin/androidx/paging/ItemKeyedDataSource.LoadParams.html">ItemKeyedDataSource.LoadParams</a>&lt;Key&gt;</code></td>
<td width="100%">
<p>Parameters for the load, including the key to load before, and requested size.</p>
</td>
</tr>
<tr>
<td><code>callback:&nbsp;<a href="/reference/kotlin/androidx/paging/ItemKeyedDataSource.LoadCallback.html">ItemKeyedDataSource.LoadCallback</a>&lt;Value&gt;</code></td>
<td width="100%">
<p>Callback that receives loaded data.</p>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<div><a name="loadInitial(androidx.paging.ItemKeyedDataSource.LoadInitialParams, androidx.paging.ItemKeyedDataSource.LoadInitialCallback)"></a><a name="loadInitial-androidx.paging.ItemKeyedDataSource.LoadInitialParams-androidx.paging.ItemKeyedDataSource.LoadInitialCallback-"></a>
<h3 class="api-name" id="loadInitial(androidx.paging.ItemKeyedDataSource.LoadInitialParams,androidx.paging.ItemKeyedDataSource.LoadInitialCallback)">loadInitial</h3>
<pre class="api-signature no-pretty-print">abstract&nbsp;fun&nbsp;<a href="/reference/kotlin/androidx/paging/ItemKeyedDataSource.html#loadInitial(androidx.paging.ItemKeyedDataSource.LoadInitialParams,androidx.paging.ItemKeyedDataSource.LoadInitialCallback)">loadInitial</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;params:&nbsp;<a href="/reference/kotlin/androidx/paging/ItemKeyedDataSource.LoadInitialParams.html">ItemKeyedDataSource.LoadInitialParams</a>&lt;Key&gt;,<br>&nbsp;&nbsp;&nbsp;&nbsp;callback:&nbsp;<a href="/reference/kotlin/androidx/paging/ItemKeyedDataSource.LoadInitialCallback.html">ItemKeyedDataSource.LoadInitialCallback</a>&lt;Value&gt;<br>):&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html">Unit</a></pre>
<p>Load initial data.</p>
<p>This method is called first to initialize a <code><a href="/reference/kotlin/androidx/paging/PagedList.html">PagedList</a></code> with data. If it's possible to count the items that can be loaded by the DataSource, it's recommended to pass the loaded data to the callback via the three-parameter <code><a href="/reference/kotlin/androidx/paging/ItemKeyedDataSource.LoadInitialCallback.html#onResult(kotlin.collections.List,kotlin.Int,kotlin.Int)">LoadInitialCallback.onResult</a></code>. This enables PagedLists presenting data from this source to display placeholders to represent unloaded items.</p>
<p><code><a href="/reference/kotlin/androidx/paging/ItemKeyedDataSource.LoadInitialParams.html#requestedInitialKey()">LoadInitialParams.requestedInitialKey</a></code> and <code><a href="/reference/kotlin/androidx/paging/ItemKeyedDataSource.LoadInitialParams.html#requestedLoadSize()">LoadInitialParams.requestedLoadSize</a></code> are hints, not requirements, so they may be altered or ignored. Note that ignoring the <code>requestedInitialKey</code> can prevent subsequent PagedList/DataSource pairs from initializing at the same location. If your DataSource never invalidates (for example, loading from the network without the network ever signalling that old data must be reloaded), it's fine to ignore the <code>initialLoadKey</code> and always start from the beginning of the data set.</p>
<div class="devsite-table-wrapper">
<table class="responsive">
<thead>
<tr>
<th colspan="2">Parameters</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>params:&nbsp;<a href="/reference/kotlin/androidx/paging/ItemKeyedDataSource.LoadInitialParams.html">ItemKeyedDataSource.LoadInitialParams</a>&lt;Key&gt;</code></td>
<td width="100%">
<p>Parameters for initial load, including initial key and requested size.</p>
</td>
</tr>
<tr>
<td><code>callback:&nbsp;<a href="/reference/kotlin/androidx/paging/ItemKeyedDataSource.LoadInitialCallback.html">ItemKeyedDataSource.LoadInitialCallback</a>&lt;Value&gt;</code></td>
<td width="100%">
<p>Callback that receives initial load data.</p>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<div><a name="map--"></a>
<h3 class="api-name" id="map()">map</h3>
<pre class="api-signature no-pretty-print">final&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/ItemKeyedDataSource.html#map()">map</a>(function:&nbsp;<a href="/reference/kotlin/[JVM root]/&lt;ERROR CLASS&gt;.html">&lt;ERROR CLASS&gt;</a>&lt;Value,&nbsp;ToValue&gt;):&nbsp;<a href="/reference/kotlin/androidx/paging/ItemKeyedDataSource.html">ItemKeyedDataSource</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/ItemKeyedDataSource.html#mapByPage()">mapByPage</a></code>, but operates on individual items.</p>
<div class="devsite-table-wrapper">
<table class="responsive">
<thead>
<tr>
<th colspan="2">Returns</th>
</tr>
</thead>
<tbody>
<tr>
<td><code><a href="/reference/kotlin/androidx/paging/ItemKeyedDataSource.html">ItemKeyedDataSource</a>&lt;Key,&nbsp;ToValue&gt;</code></td>
<td width="100%">
<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">
<thead>
<tr>
<th colspan="2">Parameters</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>&lt;ToValue&nbsp;:&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html">Any</a>&gt;</code></td>
<td width="100%">
<p>Type of items produced by the new DataSource, from the passed function.</p>
</td>
</tr>
<tr>
<td><code>function:&nbsp;<a href="/reference/kotlin/[JVM root]/&lt;ERROR CLASS&gt;.html">&lt;ERROR CLASS&gt;</a>&lt;Value,&nbsp;ToValue&gt;</code></td>
<td width="100%">
<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">
<thead>
<tr>
<th colspan="2">See also</th>
</tr>
</thead>
<tbody>
<tr>
<td><code><a href="/reference/kotlin/androidx/paging/ItemKeyedDataSource.html#mapByPage()">mapByPage</a></code></td>
<td width="100%"></td>
</tr>
<tr>
<td><code><a href="/reference/kotlin/androidx/paging/DataSource.Factory.html#map()">map</a></code></td>
<td width="100%"></td>
</tr>
<tr>
<td><code><a href="/reference/kotlin/androidx/paging/DataSource.Factory.html#mapByPage()">mapByPage</a></code></td>
<td width="100%"></td>
</tr>
</tbody>
</table>
</div>
</div>
<div><a name="map-kotlin.Function1-"></a>
<h3 class="api-name" id="map(kotlin.Function1)">map</h3>
<pre class="api-signature no-pretty-print">final&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/ItemKeyedDataSource.html#map(kotlin.Function1)">map</a>(function:&nbsp;(Value)&nbsp;-&gt;&nbsp;ToValue):&nbsp;<a href="/reference/kotlin/androidx/paging/ItemKeyedDataSource.html">ItemKeyedDataSource</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/ItemKeyedDataSource.html#mapByPage()">mapByPage</a></code>, but operates on individual items.</p>
<div class="devsite-table-wrapper">
<table class="responsive">
<thead>
<tr>
<th colspan="2">Returns</th>
</tr>
</thead>
<tbody>
<tr>
<td><code><a href="/reference/kotlin/androidx/paging/ItemKeyedDataSource.html">ItemKeyedDataSource</a>&lt;Key,&nbsp;ToValue&gt;</code></td>
<td width="100%">
<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">
<thead>
<tr>
<th colspan="2">Parameters</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>&lt;ToValue&nbsp;:&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html">Any</a>&gt;</code></td>
<td width="100%">
<p>Type of items produced by the new DataSource, from the passed function.</p>
</td>
</tr>
<tr>
<td><code>function:&nbsp;(Value)&nbsp;-&gt;&nbsp;ToValue</code></td>
<td width="100%">
<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">
<thead>
<tr>
<th colspan="2">See also</th>
</tr>
</thead>
<tbody>
<tr>
<td><code><a href="/reference/kotlin/androidx/paging/ItemKeyedDataSource.html#mapByPage()">mapByPage</a></code></td>
<td width="100%"></td>
</tr>
<tr>
<td><code><a href="/reference/kotlin/androidx/paging/DataSource.Factory.html#map()">map</a></code></td>
<td width="100%"></td>
</tr>
<tr>
<td><code><a href="/reference/kotlin/androidx/paging/DataSource.Factory.html#mapByPage()">mapByPage</a></code></td>
<td width="100%"></td>
</tr>
</tbody>
</table>
</div>
</div>
<div><a name="mapByPage--"></a>
<h3 class="api-name" id="mapByPage()">mapByPage</h3>
<pre class="api-signature no-pretty-print">final&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/ItemKeyedDataSource.html#mapByPage()">mapByPage</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;function:&nbsp;<a href="/reference/kotlin/[JVM root]/&lt;ERROR CLASS&gt;.html">&lt;ERROR CLASS&gt;</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;<br>):&nbsp;<a href="/reference/kotlin/androidx/paging/ItemKeyedDataSource.html">ItemKeyedDataSource</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/ItemKeyedDataSource.html#map()">map</a></code>, but allows for batch conversions.</p>
<div class="devsite-table-wrapper">
<table class="responsive">
<thead>
<tr>
<th colspan="2">Returns</th>
</tr>
</thead>
<tbody>
<tr>
<td><code><a href="/reference/kotlin/androidx/paging/ItemKeyedDataSource.html">ItemKeyedDataSource</a>&lt;Key,&nbsp;ToValue&gt;</code></td>
<td width="100%">
<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">
<thead>
<tr>
<th colspan="2">Parameters</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>&lt;ToValue&nbsp;:&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html">Any</a>&gt;</code></td>
<td width="100%">
<p>Type of items produced by the new DataSource, from the passed function.</p>
</td>
</tr>
<tr>
<td><code>function:&nbsp;<a href="/reference/kotlin/[JVM root]/&lt;ERROR CLASS&gt;.html">&lt;ERROR CLASS&gt;</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 width="100%">
<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">
<thead>
<tr>
<th colspan="2">See also</th>
</tr>
</thead>
<tbody>
<tr>
<td><code><a href="/reference/kotlin/androidx/paging/ItemKeyedDataSource.html#map()">map</a></code></td>
<td width="100%"></td>
</tr>
<tr>
<td><code><a href="/reference/kotlin/androidx/paging/DataSource.Factory.html#map()">map</a></code></td>
<td width="100%"></td>
</tr>
<tr>
<td><code><a href="/reference/kotlin/androidx/paging/DataSource.Factory.html#mapByPage()">mapByPage</a></code></td>
<td width="100%"></td>
</tr>
</tbody>
</table>
</div>
</div>
<div><a name="mapByPage-kotlin.Function1-"></a>
<h3 class="api-name" id="mapByPage(kotlin.Function1)">mapByPage</h3>
<pre class="api-signature no-pretty-print">final&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/ItemKeyedDataSource.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;)&nbsp;-&gt;&nbsp;<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/ItemKeyedDataSource.html">ItemKeyedDataSource</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/ItemKeyedDataSource.html#map()">map</a></code>, but allows for batch conversions.</p>
<div class="devsite-table-wrapper">
<table class="responsive">
<thead>
<tr>
<th colspan="2">Returns</th>
</tr>
</thead>
<tbody>
<tr>
<td><code><a href="/reference/kotlin/androidx/paging/ItemKeyedDataSource.html">ItemKeyedDataSource</a>&lt;Key,&nbsp;ToValue&gt;</code></td>
<td width="100%">
<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">
<thead>
<tr>
<th colspan="2">Parameters</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>&lt;ToValue&nbsp;:&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html">Any</a>&gt;</code></td>
<td width="100%">
<p>Type of items produced by the new DataSource, from the passed function.</p>
</td>
</tr>
<tr>
<td><code>function:&nbsp;(<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-list/index.html">List</a>&lt;Value&gt;)&nbsp;-&gt;&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-list/index.html">List</a>&lt;ToValue&gt;</code></td>
<td width="100%">
<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">
<thead>
<tr>
<th colspan="2">See also</th>
</tr>
</thead>
<tbody>
<tr>
<td><code><a href="/reference/kotlin/androidx/paging/ItemKeyedDataSource.html#map()">map</a></code></td>
<td width="100%"></td>
</tr>
<tr>
<td><code><a href="/reference/kotlin/androidx/paging/DataSource.Factory.html#map()">map</a></code></td>
<td width="100%"></td>
</tr>
<tr>
<td><code><a href="/reference/kotlin/androidx/paging/DataSource.Factory.html#mapByPage()">mapByPage</a></code></td>
<td width="100%"></td>
</tr>
</tbody>
</table>
</div>
</div>
</body>
</html>