title: Change a materialized value in a source using the contents of the stream
body: <p>Alpakka provides a great way to access dozens of different data sources. File oriented sources such as HDFS and FTP sources are delivered as <code>Source[ByteString, Future[IOResult]</code>. However, HTTP requests via Akka HTTP are delivered as entity streams of <code>Source[ByteString, NotUsed]</code>. In my use case, I would like to retrieve content from HTTP sources as <code>Source[ByteString, Future[IOResult]</code> so I can build a unified resource fetcher that works from multiple schemes (hdfs, file, ftp and S3 in this case). </p>
  
  <p>In particular, I would like to convert the <code>Source[ByteString, NotUsed]</code> source to 
  <code>Source[ByteString, Future[IOResult]</code> where I am able to calculate the IOResult from the incoming byte stream. There are plenty of methods like <code>flatMapConcat</code> and <code>viaMat</code> but none seem to be able to extract details from the input stream (such as number of bytes read) or initialise the <code>IOResult</code> structure properly. Ideally, I am looking for a method with the following signature that will update the IOResult as the stream comes in.</p>
  
  <pre><code>  def matCalc(src: Source[ByteString, Any]) = Source[ByteString, Future[IOResult]] = {
      src.someMatFoldMagic[ByteString, IOResult](IOResult.createSuccessful(0))(m, b) =&gt; m.withCount(m.count + b.length))
    }
  </code></pre>