title: Viewing initial data source and filtering with RxSwift using MVVM
body: <p>I'm starting out with RxSwift and trying to get a simple example of filtering a data source with a UISearchController working.</p>
  
  <p>I have the basic setup of a UISearchController wired into a UITableViewController. Using MVVM I also have a basic view model setup that will drive the table.</p>
  
  <pre><code>self.viewModel.searchText.accept(searchController.searchBar.text ?? "")
  </code></pre>
  
  <pre><code>viewModel.listItems.bind(to: tableView.rx.items(cellIdentifier: "ItemCell")) { row, item, cell in
      cell.textLabel!.text = item.name
  }
  .disposed(by: disposeBag)
  </code></pre>
  
  <p>View Model</p>
  
  <pre><code>class ListViewModel {
  
      private let sourceItems: BehaviorRelay&lt;[ListItem]&gt; = BehaviorRelay(value: [
              ListItem(name: "abc"),
              ListItem(name: "def"),
              ListItem(name: "ghi"),
              ListItem(name: "jkl"),
              ListItem(name: "mno")
          ])
  
      let searchText = BehaviorRelay&lt;String&gt;(value: "")
      var listItems: Observable&lt;[ListItem]&gt; = Observable.just([])
  
      init() {
          listItems = sourceItems.asObservable()
      }
  
  }
  </code></pre>
  
  <p>I can add in the search filtering and this works such that only the values matching the filter string will show</p>
  
  <pre><code>let searchObservable = searchText
      .throttle(.milliseconds(300), scheduler: MainScheduler.instance)
      .distinctUntilChanged()
      .filter { query in
          return query.count &gt; 2
      }
      .share(replay: 1)
  
  listItems = Observable.combineLatest(sourceItems.asObservable(), searchObservable) { items, query in
          return items.filter({ item in
              item.name.lowercased().contains(query.lowercased())
          })
      }
  </code></pre>
  
  <p>However, this will not show any values until the filter is matched. What I am trying to do is initially show all the values and then only show the filtered values.  I'm not quite sure how to populate the <code>listItems</code> when the <code>searchText</code> changes but is empty or events are filtered out.</p>