Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions streams/shared/src/main/scala/zio/stream/ZPipeline.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1844,22 +1844,23 @@ object ZPipeline extends ZPipelinePlatformSpecificConstructors {
chunk => {
val size = chunk.size

if (size == 0) reader
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In another PR, we were talking about the fact that this Chunk can probably never be empty

else if (size == 1) {
if (size == 1) {
val a = chunk.head

f(a) match {
case r: Right[?, Out] => ZChannel.write(Chunk.single(r.value)) *> reader
case l: Left[Err, ?] => ZChannel.refailCause(Cause.fail(l.value))
}
} else {
val builder: ChunkBuilder[Out] = ChunkBuilder.make[Out](chunk.size)
val iterator: Iterator[In] = chunk.iterator
val builder: ChunkBuilder[Out] = ChunkBuilder.make[Out](size)
val iterator = chunk.chunkIterator
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TIL about ChunkIterator

image

var index: Int = 0
var error: Err = null.asInstanceOf[Err]

while (iterator.hasNext && (error == null)) {
val a = iterator.next()
f(a) match {
while (index < size && error == null) {
val in = iterator.nextAt(index)
index += 1
f(in) match {
case r: Right[?, Out] => builder.addOne(r.value)
case l: Left[Err, ?] => error = l.value
}
Expand Down