Fold a String
stream using StringBuilder
instead of Monoid[String]
, because the monoid performs repeated concatenation.
@ def foldString[F[_]](src: Stream[F, String]): Stream[F, String] = src.fold(new StringBuilder)(_ append _).map(_.result)
defined function foldString
@ val s = foldString(Stream("Hello", " World!"))
s: Stream[Pure, String] = Stream(..)
@ s.toList