title: angular rxjs pipe remove element from array
body: <p>I have a service with a delete function. The delete function will call an api and it will return true or false. When true, I will lookup the index in my array, splice it and return the new array. So for example</p>
  
  <pre><code>private items = [];
  onItemDeleted  = new Subject&lt;any&gt;();
  
    delete(id:number): Observable&lt;any&gt; {
      return this.http.delete('http://my.api.com/item/' + id)
        .pipe(
          switchMap(checkServerSuccessResponse),
          map(data =&gt; {
              const index1  = this.items.findIndex((element) =&gt; {
                return element.id === id;
              });
              if (index1 &gt;= 0 ) {
                this.items.splice(index1,1);
              }
              this.onItemDeleted.next(this.items);
              return this.items;
            }
          ),
          catchError(returnFalse),
        );
    }
  </code></pre>
  
  <p>I have a helper for the switchmap :</p>
  
  <pre><code>export function checkServerSuccessResponse(data: Response): Observable&lt;any&gt; {
      return (data &amp;&amp; data['success'] === true) ? of(data) : throwError("server responded false");
  }
  </code></pre>
  
  <p>Although this works, I have a feeling the map section can reformatted. I first thought of filter (after the switchmap) to exclude the element with the id I've supplied, then emit the new array, but then I realised, the filter is not subscribed to the this.items array.</p>
  
  <p>What would be the best approach to do this?</p>