title: Android Room Paging3 correct approach for dynamic filtering
body: <p>I am investigating the new Android Room Paging library</p>
  <pre><code>   implementation &quot;androidx.paging:paging-runtime-ktx:3.0.0-alpha09&quot;
  </code></pre>
  <p>My source database tables approx 10,000 rows and I filter by the first character of the name field as follows:-</p>
  <p>DAO</p>
  <pre><code>@Query(&quot;SELECT * from citation_style WHERE citation_style_name LIKE :startsWith ORDER BY citation_style_name ASC&quot;)
  fun fetch(startsWith: String): PagingSource&lt;Int, CitationStyleDO&gt;
  </code></pre>
  <p>Repository</p>
  <pre><code>fun fetch(startsWith: String): Flow&lt;PagingData&lt;CitationStyleDO&gt;&gt; {
      return Pager(
          PagingConfig(pageSize = 60, prefetchDistance = 30, enablePlaceholders = false, maxSize = 200)
      ) { database.citationStyleDao().fetch(&quot;$startsWith%&quot;) }.flow
  }
  </code></pre>
  <p>ViewModel</p>
  <pre><code>fun fetch(startsWith: String): Flow&lt;PagingData&lt;CitationStyleDO&gt;&gt; {
      return repository.fetch(startsWith).cachedIn(viewModelScope)
  }
  </code></pre>
  <p>Fragment</p>
  <pre><code>override fun onStartsWithClicked(startsWith: String) {
      lifecycleScope.launch {
          viewModel.fetch(startsWith).collectLatest { adapter.submitData(it) }
      }
  }
  </code></pre>
  <p>Is this the correct approach of repeatedly using <code>lifecycleScope.launch {...}</code> each time the Starts With character is changed?</p>
  <p>Should I be <code>map{}</code> or <code>switchMap{}</code> triggered by a <code>MutabaleLiveData&lt;String&gt;</code> for StartwWith?</p>