Skip to content

Commit

Permalink
Implement unchunks (inverse of chunks)
Browse files Browse the repository at this point in the history
  • Loading branch information
armanbilge committed Jul 26, 2021
1 parent e106311 commit c057333
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 4 additions & 0 deletions core/shared/src/main/scala/fs2/Stream.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2596,6 +2596,10 @@ final class Stream[+F[_], +O] private[fs2] (private[fs2] val underlying: Pull[F,
}
}

/** Flattens a stream of chunks. Inverse of [[chunks]]. */
def unchunks[O2](implicit ev: O <:< Chunk[O2]): Stream[F, O2] =
flatMap(Stream.chunk(_))

/** Alias for [[filter]]
* Implemented to enable filtering in for comprehensions
*/
Expand Down
4 changes: 2 additions & 2 deletions core/shared/src/test/scala/fs2/StreamSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,10 @@ class StreamSuite extends Fs2Suite {
}
}

property("chunks.flatMap(chunk) identity") {
property("chunks.unchunks identity") {
forAll { (v: Vector[Vector[Int]]) =>
val s = if (v.isEmpty) Stream.empty else v.map(Stream.emits).reduce(_ ++ _)
assertEquals(s.chunks.flatMap(Stream.chunk).toVector, v.flatten)
assertEquals(s.chunks.unchunks.toVector, v.flatten)
}
}
}
Expand Down

0 comments on commit c057333

Please sign in to comment.