title: How to get templates always before models in Rxjs
body: <p>I have Angular service where need to conditionally map models using templateForPercentage or templateForCurrency it only in case addExpensesItemCurrency and addExpensesItemPercent subscription get response BEFORE this.getExpensesGroups(id) gets response. What operator or combination of operators would u suggest to use to get both templates AND value emitted by <code>switchMap(id =&gt; this.getExpensesGroups(id))</code> row:</p>
  
  <pre><code>templateForCurrency$ = new BehaviorSubject&lt;Model&gt;(null);
  templateForPercentage$ = new BehaviorSubject&lt;Model&gt;(null);
  templateForPercentage: Model;
  templateForCurrency: Model;
  
  constructor() {
    this.projectIdState$.pipe(
      tap(p =&gt; console.log('fetched expenses for project', p)),
      tap(id =&gt; { if (!id || id === "admin-areas") this.expensesState = initialExpensesState }),
      filter(id =&gt; id &amp;&amp; id !== "admin-areas"),
      switchMap(id =&gt; this.getExpensesGroups(id))
  
      // i guess here should be some operators to get templates
      // this.templateForCurrency$.pipe(
      //   switchMap(template =&gt; template ? Observable.of(template) : this.addExpensesItemCurrency())
    // )  
  
    // this.templateForPercent$.pipe(
      //   switchMap(template =&gt; template ? Observable.of(template) : this.addExpensesItemPercent())
    // )  
  
    // I guess it should return something like that  [ExpenseGroup, templateForCurrency, templateForPercent]
  
    }).subscribe((response: ExpenseGroup[]) =&gt; {
      this.expensesState = {
        ...this.expensesState,
        expenseGroupsToExpose: [...response.map(g =&gt; ({
          ...g, models: g.models.map(m =&gt; this.mapExpenseModel(m))
        }))],
        isLoading: false
      }})
  
      this.addExpensesItemCurrency().subscribe(
        template =&gt; this.templateForCurrency = template
      )
  
      this.addExpensesItemPercent().subscribe(
        template =&gt; this.templateForPercentage = template
      )
    }
  }
  
  private mapExpenseModel(model) {
    const template = this.setTemplate(model.subType);
  
    return {
      ...model,
      ...template,
      initialSubType: model.subType,
      shouldSave: true
    }
  }
  
  private setTemplate(subType: string) {
    if (subType === "EXPENSE_ABS_CURRENCY") {
      return {template: this.templateForPercentage.fields};
    } else if (subType === "EXPENSE_ABS_PERCENT") {
      return {template: this.templateForCurrency.fields};
    } else {
      return {};
    }
  }
  </code></pre>