Merge pull request #19407 from akka/wip-optimize-repeat-√
=str - Change implementation of Source.repeat to use unfold
This commit is contained in:
commit
3267d58e5d
1 changed files with 4 additions and 8 deletions
|
|
@ -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
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue