Skip to content

Commit b939a1f

Browse files
committed
Slight refactor of chunk reduction
1 parent 87f3229 commit b939a1f

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

core/shared/src/main/scala/fs2/Stream.scala

+2-4
Original file line numberDiff line numberDiff line change
@@ -594,7 +594,7 @@ final class Stream[+F[_], +O] private[fs2] (private[fs2] val underlying: Pull[F,
594594
def conflate1[F2[x] >: F[x]: Concurrent, O2 >: O](chunkLimit: Int)(
595595
f: (O2, O2) => O2
596596
): Stream[F2, O2] =
597-
conflateChunks[F2](chunkLimit).map(c => c.drop(1).foldLeft(c(0): O2)((x, y) => f(x, y)))
597+
conflateChunks[F2](chunkLimit).map(_.iterator.reduce(f))
598598

599599
/** Like `conflate1` but combines elements using the semigroup of the output type.
600600
*/
@@ -608,9 +608,7 @@ final class Stream[+F[_], +O] private[fs2] (private[fs2] val underlying: Pull[F,
608608
def conflateMap[F2[x] >: F[x]: Concurrent, O2: Semigroup](
609609
chunkLimit: Int
610610
)(f: O => O2): Stream[F2, O2] =
611-
conflateChunks[F2](chunkLimit).map(c =>
612-
c.drop(1).foldLeft(f(c(0)))((x, y) => Semigroup[O2].combine(x, f(y)))
613-
)
611+
conflateChunks[F2](chunkLimit).map(_.iterator.map(f).reduce(Semigroup[O2].combine))
614612

615613
/** Prepends a chunk onto the front of this stream.
616614
*

0 commit comments

Comments
 (0)