str #20262 reduce should fail explicitly on empty stream (#20267)

* str #20262 reduce should fail explicitly on empty stream

* str #20262 document reduce behaviour on empty stream
This commit is contained in:
Konrad Malawski 2016-04-11 15:36:10 +02:00
parent 503a77f515
commit b9ab232cac
8 changed files with 67 additions and 14 deletions

View file

@ -107,6 +107,11 @@ final class Source[+Out, +Mat](private[stream] override val module: Module)
* The returned [[scala.concurrent.Future]] will be completed with value of the final
* function evaluation when the input stream ends, or completed with `Failure`
* if there is a failure signaled in the stream.
*
* If the stream is empty (i.e. completes before signalling any elements),
* the reduce stage will fail its downstream with a [[NoSuchElementException]],
* which is semantically in-line with that Scala's standard library collections
* do in such situations.
*/
def runReduce[U >: Out](f: (U, U) U)(implicit materializer: Materializer): Future[U] =
runWith(Sink.reduce(f))