title: Handle observables in sequence and wait for user input
body: <p>I have an array of items that I need to iterate over to check whether or not to display a modal dialog to the user, and wait for the user input before I continue the iteration. The array is wrapped inside an observable like <code>Observable&lt;Array&lt;Item&gt;&gt;;</code>.</p>
  
  <p>For each item in the array, I need to check if it's type is already present in a <code>Map&lt;ItemType, string&gt;</code> object. If it isn't present, a modal where the user inputs a comment should be displayed, and the input value should be stored in the map. If it's present, nothing should be done and the iteration should continue. I've written some pseudo code on what I want to achieve below.</p>
  
  <pre><code>Map&lt;ItemType, string&gt; comments;
  Observable&lt;Array&lt;Items&gt;&gt; items;
  
  foreach (item in items) {
      if(comments[item.type]) {
          continue to next item;
      } else {
          show a modal dialog and wait for the userInput;
          onModalClose -&gt; comments[item.type] = userInput
      }
  }
  </code></pre>
  
  <p>The modal itself returns a new observable wrapping the user input.</p>
  
  <p>What I can't wrap my head around is how to wait for the modal observable to complete before I continue on with the iteration of the observable array, <em>the RxJs way</em>. Doing it with promise chains wouldn't be too confusing. </p>
  
  <p>I've tried multiple ways but I'm now probably to confused by my attempts to see it clearly. </p>
  
  <p>My last attempt is as below, though I'm pretty sure it's far from what it should be like.</p>
  
  <pre><code>this.items$.pipe( //Observable&lt;Array&lt;Item&gt;&gt;
        map(items =&gt; items.map(i =&gt; of(i))), //Convert to an Array&lt;Observable&lt;Item&gt;&gt;
        switchMap(items =&gt; { 
          return concat(...items).pipe(
            switchMap(item =&gt; {
              return this.showExtraInformationModal().pipe(
                map(resultFromModal =&gt; {
                  // Use the result from modal 
                })
              );
            })
          )
        })
      ).subscribe();
  </code></pre>
  
  <p>What is the proper way to handle the <em>"Wait for user input and then continue!"</em> scenario with observables?</p>