How to remove an object from an array in Immutable?
<p>Given a state like this:</p>

<pre><code>state = {
  things: [
    { id: 'a1', name: 'thing 1' },
    { id: 'a2', name: 'thing 2' },
  ],
};
</code></pre>

<p>How can I create a new state where ID "a1" is removed? It's easy enough to push new items:</p>

<pre><code>return state.set(state.get('things').push(newThing));
</code></pre>

<p>But I can't figure out how to search for and remove an object by its <code>id</code> property. I tried this:</p>

<pre><code>return state.set('tracks',
  state.get('tracks').delete(
    state.get('tracks').findIndex(x =&gt; x.get('id') === 'a2')
  )
)
</code></pre>

<p>But it seems messy, plus it only works if the item is found, because if <code>findIndex</code> returns <code>-1</code>, that's a valid value for <code>delete</code>.</p>