=str - Change implementation of Source.repeat to use unfold

This commit is contained in:
Viktor Klang 2016-01-12 10:52:09 +01:00
parent 84fd5a9b2a
commit 2b1d22a785

View file

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