Using rest of stream after Stream.take(1)
<p>I'm using a library to read a csv file which returns a stream of rows:</p>

<pre><code>File.stream!("some_file.csv")
|&gt; CSV.decode  # returns a stream of rows
</code></pre>

<p>The first row is usually the csv header, so I thought it would be cool to split header and body:</p>

<pre><code>def split_header_and_body(row_stream) do
  header = row_stream |&gt; Stream.take(1) |&gt; Enum.to_list |&gt; List.first
  body = row_stream |&gt; Stream.drop(1)

  {header, body}
end
</code></pre>

<p>This doesn't work, probably because <code>Stream.take/1</code> ends enumeration (as stated in the docs).</p>

<p>I thought everything is immutable, so I can just reuse the initial <code>row_stream</code>, but this is not the case and I couldn't find out how to duplicate the stream either.</p>