title: RXJS : Idiomatic way to create an observable stream from a paged interface
body: <p>I have paged interface. Given a starting point a request will produce a list of results and a continuation indicator.</p>
  <p>I've created an observable that is built by constructing and flat mapping an observable that reads the page. The result of this observable contains both the data for the page and a value to continue with. I pluck the data and flat map it to the subscriber. Producing a stream of values.</p>
  <p>To handle the paging I've created a subject for the next page values. It's seeded with an initial value then each time I receive a response with a valid next page I push to the pages subject and trigger another read until such time as there is no more to read.</p>
  <p>Is there a more idiomatic way of doing this?</p>
  <pre class="lang-js prettyprint-override"><code>    function records(start = 'LATEST', limit = 1000) {
        let pages = new rx.Subject();
  
        this.connect(start)
          .subscribe(page =&gt; pages.onNext(page));
  
        let records = pages
          .flatMap(page =&gt; {
            return this.read(page, limit)
              .doOnNext(result =&gt; {
                let next = result.next;
                if (next === undefined) {
                  pages.onCompleted();
                } else {
                  pages.onNext(next);
                }
              });
          })
          .pluck('data')
          .flatMap(data =&gt; data);
  
        return records;
      }
  </code></pre>