Merge pull request #19407 from akka/wip-optimize-repeat-√

=str - Change implementation of Source.repeat to use unfold
This commit is contained in:
Roland Kuhn 2016-01-14 08:09:04 +01:00
commit 3267d58e5d

View file

@ -237,14 +237,10 @@ object Source {
/** /**
* Create a `Source` that will continually emit the given element. * Create a `Source` that will continually emit the given element.
*/ */
def repeat[T](element: T): Source[T, Unit] = def repeat[T](element: T): Source[T, Unit] = {
single(new immutable.Iterable[T] { val next = Some((element, element))
override val iterator: Iterator[T] = Iterator.continually(element) unfold(element)(_ => next).withAttributes(DefaultAttributes.repeat)
}
override def toString: String = "repeat(" + element + ")"
})
.mapConcat(ConstantFun.scalaIdentityFunction)
.withAttributes(DefaultAttributes.repeat)
/** /**
* Create a `Source` that will unfold a value of type `S` into * Create a `Source` that will unfold a value of type `S` into