title: ReactiveX: filter out numbers from observable so that total never goes below zero
body: <p>The following RxJs code displays numbers from the input list and the running total:</p>
  
  <pre><code>let inputs = [10, 10, -30, 10, -30, 50, -25, -30, 10]
  
  let obs$ = Rx.Observable.from(inputs)
  let totals$ = obs$.scan((acc, next) =&gt; acc + next, 0)
  obs$.subscribe(x =&gt; console.log('x:', x));
  totals$.subscribe(x =&gt; console.log("total:", x))
  </code></pre>
  
  <p><code>totals$</code> will emit: 10, 20, -10, 0, -30...</p>
  
  <p>I would like to transform the <code>obs$</code> observable somehow, so that the resulting <code>totals$</code> never emits a negative number.</p>
  
  <p>I.e., in this case, both first and last "-30" should be filtered out:</p>
  
  <p><code>otherObs$</code>: 10, 10, 10, -30, 50, -25, 10</p>
  
  <p><code>totals$</code>: 10, 20, 30, 0, 50, 25, 35</p>
  
  <p>edit: Note that I'm interested in the modified <code>otherObs$</code> observable, i.e., a sequence of the original input numbers with some filtered out (<code>obs$</code> will actually contain more data, so I really do need the original elements; the "value" is just a key to filter on). The <code>totals$</code> here is <em>only</em> for showing what is going on.</p>