title: rxjs - startWith based on Observable with initial value
body: <p>I have a data source with query, sort and pagination features. All of these are defined as BehaviourSubjects. I am trying to implement state saving the of the table, restoring the query, sort and pagination values.</p>
  <p>Currently I have the code below that is responsible for it:</p>
  <pre><code>// params restored from storage
  const pageSize = this.params.page?.pageSize ?? 20;
  this.pageIndex = this.params.page?.pageIndex ?? 0;
  
  query = new BehaviorSubject&lt;Q | undefined&gt;(params.query);
  sort = new BehaviorSubject&lt;Sort&lt;T&gt; | undefined&gt;(params.sort);
  page = new Subject&lt;PageEvent&gt;();
  </code></pre>
  <p>Code that manages data query:</p>
  <pre><code>combineLatest([this.query, this.sort])
  .pipe(
    switchMap(([query, sort]) =&gt; this.page.pipe(
      // combine pageIndex: 0 for query, sort change
      startWith({ pageIndex: this.pageIndex, pageSize } as PageEvent), 
      map(page =&gt; [
        this.storeParams({ query, sort, page }),
        this.store.dispatch(
          this.selectAction({ query, page: page.pageIndex, sort, size: page.pageSize })
        )
      ]),
      catchError(error =&gt; of()),
    ))
  );
  </code></pre>
  <p>It works properly but when sort or query values change, I need to reset pageIndex to 0. If I use startWith with pageIndex equal to 0, then I loose the ability to restore page values from storage.</p>
  <p>To achieve it I reset the pageIndex on sort and query functions:</p>
  <pre><code>sortBy(sort: Sort&lt;T&gt;): void {
    this.pageIndex = 0; // need to remove
    this.sort.next(sort);
  }
  
  queryBy(query: Partial&lt;Q&gt;): void {
    this.pageIndex = 0; // need to remove
    this.query.next(query as Q);
  }
  </code></pre>
  <p>How is it possible to achive this using a single operator, i.e. the combineLatest above?</p>