title: Split string and skip empty substrings
body: <p>I am learning Rust and discovered this problem:</p>
  <p>I would like to split a string by a pattern and remove all cases where the resultin substring is empty.</p>
  <p>Here is an example:</p>
  <pre><code>let s = &quot;s,o,m,e,&quot;;
  for elem in s.split(&quot;,&quot;).skip_while(|&amp;x| x.is_empty()) {
      print!(&quot; &lt;{}&gt; &quot;, elem);
      //print!(&quot; &lt;{}&gt;({}) &quot;, elem, elem.is_empty());
  }
  </code></pre>
  <p>But the result is the following:</p>
  <pre><code> &lt;s&gt;  &lt;o&gt;  &lt;m&gt;  &lt;e&gt;  &lt;&gt; 
  </code></pre>
  <p>My thoughts were: The struct <code>Split</code> returned by <code>split</code> implements <code>Iterator</code> which provides <code>skip_while</code>. IntelliSense told me the <code>x</code> in the closure is of type <code>&amp;&amp;str</code> so I would assume all the elements of the iterator (of type <code>&amp;str</code>) which are empty to be omitted.</p>
  <p>But it doesn't skip the empty substring.</p>
  <p>I also tried to print the result of the <code>is_empty</code> function. It shows that the last slice is indeed empty. If I instead for the skip_while use <code>skip_while(|&amp;x| x == &quot;s&quot;)</code>, it correctly leaves out the <code>&quot;s&quot;</code> (printed with <code>is_empty</code> here):</p>
  <pre><code> &lt;o&gt;(false)  &lt;m&gt;(false)  &lt;e&gt;(false)  &lt;&gt;(true)
  </code></pre>
  <p>So somehow the slice behaves differently in the iterator?</p>
  <p>Why is that or where am I mistaken?</p>