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
25 changes: 13 additions & 12 deletions docs/reference/stream/zpipeline.md
Original file line number Diff line number Diff line change
Expand Up @@ -231,17 +231,18 @@ val lines: ZStream[Any, Throwable, String] =
2. **Composing ZPipeline with ZSink** — One pipeline can be composed with a sink, resulting in a sink that processes elements by piping them through the pipeline and piping the results into the sink:

```scala mdoc:silent:nest
val refine: ZIO[Any, Throwable, Long] =
ZStream
.fromFileName("file.txt")
.via(
ZPipeline.utf8Decode >>> ZPipeline.splitLines >>> ZPipeline.filter[String](_.contains('₿'))
)
.run(
ZSink
.fromFileName("file.refined.txt")
.contramapChunks[String](
_.flatMap(line => (line + System.lineSeparator()).getBytes())
)
import java.nio.charset.CharacterCodingException

val refine: ZIO[Any, Throwable, Long] = {
val stream: ZStream[Any, Throwable, Byte] = ZStream.fromFileName("file.txt")
val pipeline: ZPipeline[Any, CharacterCodingException, Byte, String] =
ZPipeline.utf8Decode >>> ZPipeline.splitLines >>> ZPipeline.filter[String](_.contains('₿'))
val fileSink: ZSink[Any, Throwable, String, Byte, Long] = ZSink
.fromFileName("file.refined.txt")
.contramapChunks[String](
_.flatMap(line => (line + System.lineSeparator()).getBytes())
)
val pipeSink: ZSink[Any, Throwable, Byte, Byte, Long] = pipeline >>> fileSink
stream >>> pipeSink
}
```