Skip to content

Commit

Permalink
Merge pull request #341 from scala-steward/update/zio-2.0.0-RC1
Browse files Browse the repository at this point in the history
Update zio, zio-streams, zio-test, ... to 2.0.0-RC1
  • Loading branch information
vigoo authored Jan 8, 2022
2 parents 7bf4463 + be8a1ab commit ba39493
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 82 deletions.
6 changes: 3 additions & 3 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ val scala213 = "2.13.7"
val scala3 = "3.1.0"

val zioVersion = "1.0.13"
val zio2Version = "2.0.0-M4"
val zio2Version = "2.0.0-RC1"

val scalacOptions212 = Seq("-Ypartial-unification", "-deprecation", "-target:jvm-1.8")
val scalacOptions213 = Seq("-deprecation", "-target:jvm-1.8")
Expand Down Expand Up @@ -124,7 +124,7 @@ lazy val proxZStream2 = Project("prox-zstream-2", file("prox-zstream-2")).settin
libraryDependencies ++= Seq(
"dev.zio" %% "zio" % zio2Version,
"dev.zio" %% "zio-streams" % zio2Version,
"dev.zio" %% "zio-prelude" % "1.0.0-RC5+45-aa9e4694-SNAPSHOT",
"dev.zio" %% "zio-prelude" % "1.0.0-RC9",

"dev.zio" %% "zio-test" % zio2Version % "test",
"dev.zio" %% "zio-test-sbt" % zio2Version % "test",
Expand All @@ -138,7 +138,7 @@ lazy val proxJava9 = Project("prox-java9", file("prox-java9")).settings(commonSe
lazy val docs = project
.enablePlugins(GhpagesPlugin, SiteScaladocPlugin, ScalaUnidocPlugin, MicrositesPlugin)
.settings(
addCompilerPlugin("org.typelevel" %% s"kind-projector" % "0.13.0" cross CrossVersion.full),
addCompilerPlugin("org.typelevel" %% s"kind-projector" % "0.13.2" cross CrossVersion.full),
publishArtifact := false,
skip in publish := true,
scalaVersion := scala213,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import java.io
import java.io.IOException

import zio.prelude.Identity
import zio.stream.{ZSink, ZStream, ZTransducer}
import zio.stream.{ZSink, ZStream, ZPipeline}
import zio._

import scala.language.implicitConversions
Expand All @@ -17,8 +17,8 @@ trait ProxZStream extends Prox {
transform(s).run(sink)
}
object TransformAndSink {
def apply[A, B](transducer: ZTransducer[Any, ProxError, A, B], sink: ZSink[Any, ProxError, B, Any, Unit]): TransformAndSink[A, B] =
TransformAndSink(_.transduce(transducer), sink)
def apply[A, B](transducer: ZPipeline[Any, ProxError, A, B], sink: ZSink[Any, ProxError, B, Any, Unit]): TransformAndSink[A, B] =
TransformAndSink(_.via(transducer), sink)
}

override type ProxExitCode = zio.ExitCode
Expand Down Expand Up @@ -93,10 +93,10 @@ trait ProxZStream extends Prox {
s.runCollect.map(_.toVector)

protected override final def foldStream[A, B](s: ProxStream[A], init: B, f: (B, A) => B): ProxIO[B] =
s.fold(init)(f)
s.runFold(init)(f)

protected override final def foldMonoidStream[A: Identity](s: ProxStream[A]): ProxIO[A] =
s.fold(Identity[A].identity)((a, b) => Identity[A].combine(a, b))
s.runFold(Identity[A].identity)((a, b) => Identity[A].combine(a, b))

protected override final def streamThrough[A, B](s: ProxStream[A], pipe: ProxPipe[A, B]): ProxStream[B] =
pipe(s)
Expand Down Expand Up @@ -138,8 +138,8 @@ trait ProxZStream extends Prox {
protected override final def startFiber[A](f: ProxIO[A]): ProxIO[ProxFiber[A]] =
f.fork

implicit def transducerAsPipe[A, B](transducer: ZTransducer[Any, ProxError, A, B]): ProxPipe[A, B] =
(s: ProxStream[A]) => s.transduce(transducer)
implicit def transducerAsPipe[A, B](transducer: ZPipeline[Any, ProxError, A, B]): ProxPipe[A, B] =
(s: ProxStream[A]) => s.via(transducer)

implicit def sinkAsTransformAndSink[A](sink: ZSink[Any, ProxError, A, Any, Unit]): TransformAndSink[A, A] =
TransformAndSink(identity[ZStream[Any, ProxError, A]] _, sink)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package io.github.vigoo.prox.tests.zstream
import io.github.vigoo.prox.zstream._
import io.github.vigoo.prox.{UnknownProxError, zstream}
import zio.{Clock, _}
import zio.stream.{ZSink, ZStream, ZTransducer}
import zio.stream.{ZSink, ZStream, ZPipeline}
import zio.test.Assertion._
import zio.test.TestAspect._
import zio.test._
Expand All @@ -19,7 +19,7 @@ object ProcessGroupSpecs extends DefaultRunnableSpec with ProxSpecHelpers {
suite("Piping")(
test("is possible with two") {

val processGroup = (Process("echo", List("This is a test string")) | Process("wc", List("-w"))) ># ZTransducer.utf8Decode
val processGroup = (Process("echo", List("This is a test string")) | Process("wc", List("-w"))) ># ZPipeline.utf8Decode
val program = processGroup.run().map(_.output.trim)

assertM(program)(equalTo("5"))
Expand All @@ -32,7 +32,7 @@ object ProcessGroupSpecs extends DefaultRunnableSpec with ProxSpecHelpers {
Process("sort") |
Process("uniq", List("-c")) |
Process("head", List("-n 1"))
) >? (ZTransducer.utf8Decode >>> ZTransducer.splitLines)
) >? (ZPipeline.utf8Decode >>> ZPipeline.splitLines)

val program = processGroup.run().map(
r => r.output.map(_.stripLineEnd.trim).filter(_.nonEmpty)
Expand All @@ -43,12 +43,12 @@ object ProcessGroupSpecs extends DefaultRunnableSpec with ProxSpecHelpers {

test("is customizable with pipes") {
val customPipe = (s: zstream.ProxStream[Byte]) => s
.transduce(ZTransducer.utf8Decode >>> ZTransducer.splitLines)
.via(ZPipeline.utf8Decode >>> ZPipeline.splitLines)
.map(_.split(' ').toVector)
.map(v => v.map(_ + " !!!").mkString(" "))
.intersperse("\n")
.flatMap(s => ZStream.fromIterable(s.getBytes(StandardCharsets.UTF_8)))
val processGroup = Process("echo", List("This is a test string")).via(customPipe).to(Process("wc", List("-w"))) ># ZTransducer.utf8Decode
val processGroup = Process("echo", List("This is a test string")).via(customPipe).to(Process("wc", List("-w"))) ># ZPipeline.utf8Decode
val program = processGroup.run().map(_.output.trim)

assertM(program)(equalTo("10"))
Expand All @@ -57,7 +57,7 @@ object ProcessGroupSpecs extends DefaultRunnableSpec with ProxSpecHelpers {
test("can be mapped") {
import zstream.Process._

val processGroup1 = (Process("!echo", List("This is a test string")) | Process("!wc", List("-w"))) ># ZTransducer.utf8Decode
val processGroup1 = (Process("!echo", List("This is a test string")) | Process("!wc", List("-w"))) ># ZPipeline.utf8Decode
val processGroup2 = processGroup1.map(new ProcessGroup.Mapper[String, Unit] {
override def mapFirst[P <: Process[zstream.ProxStream[Byte], Unit]](process: P): P = process.withCommand(process.command.tail).asInstanceOf[P]

Expand Down Expand Up @@ -122,7 +122,7 @@ object ProcessGroupSpecs extends DefaultRunnableSpec with ProxSpecHelpers {
test("can be fed with an input stream") {

val stream = ZStream("This is a test string").flatMap(s => ZStream.fromIterable(s.getBytes(StandardCharsets.UTF_8)))
val processGroup = (Process("cat") | Process("wc", List("-w"))) < stream ># ZTransducer.utf8Decode
val processGroup = (Process("cat") | Process("wc", List("-w"))) < stream ># ZPipeline.utf8Decode
val program = processGroup.run().map(_.output.trim)

assertM(program)(equalTo("5"))
Expand All @@ -133,7 +133,7 @@ object ProcessGroupSpecs extends DefaultRunnableSpec with ProxSpecHelpers {
withTempFile { tempFile =>
val program = for {
_ <- ZIO.attempt(Files.write(tempFile.toPath, "This is a test string".getBytes("UTF-8"))).mapError(UnknownProxError.apply)
processGroup = (Process("cat") | Process("wc", List("-w"))) < tempFile.toPath ># ZTransducer.utf8Decode
processGroup = (Process("cat") | Process("wc", List("-w"))) < tempFile.toPath ># ZPipeline.utf8Decode
result <- processGroup.run()
} yield result.output.trim

Expand All @@ -148,7 +148,7 @@ object ProcessGroupSpecs extends DefaultRunnableSpec with ProxSpecHelpers {
val processGroup = (Process("echo", List("This is a test string")) | Process("wc", List("-w"))) > tempFile.toPath
val program = for {
_ <- processGroup.run()
contents <- ZStream.fromFile(tempFile.toPath, 1024).transduce(ZTransducer.utf8Decode).fold("")(_ + _).mapError(UnknownProxError.apply)
contents <- ZStream.fromFile(tempFile, 1024).via(ZPipeline.utf8Decode).runFold("")(_ + _).mapError(UnknownProxError.apply)
} yield contents.trim

assertM(program)(equalTo("5"))
Expand All @@ -161,7 +161,7 @@ object ProcessGroupSpecs extends DefaultRunnableSpec with ProxSpecHelpers {

val p1 = Process("perl", List("-e", """print STDERR "Hello""""))
val p2 = Process("perl", List("-e", """print STDERR "world""""))
val processGroup = (p1 | p2) !># ZTransducer.utf8Decode
val processGroup = (p1 | p2) !># ZPipeline.utf8Decode
val program = processGroup.run()

program.map { result =>
Expand Down Expand Up @@ -199,7 +199,7 @@ object ProcessGroupSpecs extends DefaultRunnableSpec with ProxSpecHelpers {
val p1 = Process("perl", List("-e", """print STDERR "Hello""""))
val p2 = Process("perl", List("-e", """print STDERR "world!""""))

val stream = (ZTransducer.utf8Decode >>> ZTransducer.splitLines).map(_.length)
val stream = ZPipeline.utf8Decode >>> ZPipeline.splitLines >>> ZPipeline.map(_.length)

val processGroup = (p1 | p2) !>? stream
val program = processGroup.run()
Expand All @@ -217,7 +217,7 @@ object ProcessGroupSpecs extends DefaultRunnableSpec with ProxSpecHelpers {

val p1 = Process("perl", List("-e", """print STDERR "Hello""""))
val p2 = Process("perl", List("-e", """print STDERR "world""""))
val processGroup = (p1 | p2) drainErrors ZTransducer.utf8Decode
val processGroup = (p1 | p2) drainErrors ZPipeline.utf8Decode
val program = processGroup.run()

program.map { result =>
Expand All @@ -234,7 +234,7 @@ object ProcessGroupSpecs extends DefaultRunnableSpec with ProxSpecHelpers {
val p1 = Process("perl", List("-e", "print STDERR 'Hello\nworld'"))
val p2 = Process("perl", List("-e", "print STDERR 'Does\nit\nwork?'"))
val processGroup = (p1 | p2).foldErrors(
ZTransducer.utf8Decode >>> ZTransducer.splitLines,
ZPipeline.utf8Decode >>> ZPipeline.splitLines,
Vector.empty,
(l: Vector[Option[Char]], s: String) => l :+ s.headOption
)
Expand All @@ -255,8 +255,8 @@ object ProcessGroupSpecs extends DefaultRunnableSpec with ProxSpecHelpers {
val p1 = Process("perl", List("-e", """print STDERR "Hello""""))
val p2 = Process("perl", List("-e", """print STDERR "world""""))
val processGroup = (p1 | p2).customizedPerProcess.errorsToFoldMonoid {
case p if p == p1 => ZTransducer.utf8Decode.map(s => "P1: " + s)
case p if p == p2 => ZTransducer.utf8Decode.map(s => "P2: " + s)
case p if p == p1 => ZPipeline.utf8Decode >>> ZPipeline.map(s => "P1: " + s)
case p if p == p2 => ZPipeline.utf8Decode >>> ZPipeline.map(s => "P2: " + s)
}
val program = processGroup.run()

Expand Down Expand Up @@ -299,11 +299,11 @@ object ProcessGroupSpecs extends DefaultRunnableSpec with ProxSpecHelpers {
val p1 = Process("perl", List("-e", """print STDERR "Hello""""))
val p2 = Process("perl", List("-e", """print STDERR "world!""""))

val stream = (ZTransducer.utf8Decode >>> ZTransducer.splitLines).map(_.length)
val stream = ZPipeline.utf8Decode >>> ZPipeline.splitLines >>> ZPipeline.map(_.length)

val processGroup = (p1 | p2).customizedPerProcess.errorsToVector {
case p if p == p1 => stream.map(l => (1, l))
case p if p == p2 => stream.map(l => (2, l))
case p if p == p1 => stream >>> ZPipeline.map(l => (1, l))
case p if p == p2 => stream >>> ZPipeline.map(l => (2, l))
}
val program = processGroup.run()

Expand All @@ -320,7 +320,7 @@ object ProcessGroupSpecs extends DefaultRunnableSpec with ProxSpecHelpers {

val p1 = Process("perl", List("-e", """print STDERR "Hello""""))
val p2 = Process("perl", List("-e", """print STDERR "world""""))
val processGroup = (p1 | p2).customizedPerProcess.drainErrors(_ => ZTransducer.utf8Decode)
val processGroup = (p1 | p2).customizedPerProcess.drainErrors(_ => ZPipeline.utf8Decode)
val program = processGroup.run()

program.map { result =>
Expand All @@ -338,8 +338,8 @@ object ProcessGroupSpecs extends DefaultRunnableSpec with ProxSpecHelpers {
val p2 = Process("perl", List("-e", "print STDERR 'Does\nit\nwork?'"))
val processGroup = (p1 | p2).customizedPerProcess.foldErrors(
{
case p if p == p1 => ZTransducer.utf8Decode >>> ZTransducer.splitLines
case p if p == p2 => (ZTransducer.utf8Decode >>> ZTransducer.splitLines).map(_.reverse)
case p if p == p1 => ZPipeline.utf8Decode >>> ZPipeline.splitLines
case p if p == p2 => ZPipeline.utf8Decode >>> ZPipeline.splitLines >>> ZPipeline.map(_.reverse)
},
Vector.empty,
(l: Vector[Option[Char]], s: String) => l :+ s.headOption
Expand Down Expand Up @@ -367,8 +367,8 @@ object ProcessGroupSpecs extends DefaultRunnableSpec with ProxSpecHelpers {
}
val program = for {
_ <- processGroup.run()
contents1 <- ZStream.fromFile(tempFile1.toPath, 1024).transduce(ZTransducer.utf8Decode).fold("")(_ + _).mapError(UnknownProxError.apply)
contents2 <- ZStream.fromFile(tempFile2.toPath, 1024).transduce(ZTransducer.utf8Decode).fold("")(_ + _).mapError(UnknownProxError.apply)
contents1 <- ZStream.fromFile(tempFile1, 1024).via(ZPipeline.utf8Decode).runFold("")(_ + _).mapError(UnknownProxError.apply)
contents2 <- ZStream.fromFile(tempFile2, 1024).via(ZPipeline.utf8Decode).runFold("")(_ + _).mapError(UnknownProxError.apply)
} yield (contents1, contents2)

assertM(program)(equalTo(("Hello", "world")))
Expand All @@ -384,7 +384,7 @@ object ProcessGroupSpecs extends DefaultRunnableSpec with ProxSpecHelpers {
val p1 = Process("perl", List("-e", """my $str=<>; print STDERR Hello; print STDOUT "$str""""))
val p2 = Process("sort")
val p3 = Process("wc", List("-w"))
val processGroup = (p1 | p2 | p3) < stream ># ZTransducer.utf8Decode !># ZTransducer.utf8Decode
val processGroup = (p1 | p2 | p3) < stream ># ZPipeline.utf8Decode !># ZPipeline.utf8Decode

processGroup.run()
.map { result =>
Expand All @@ -401,7 +401,7 @@ object ProcessGroupSpecs extends DefaultRunnableSpec with ProxSpecHelpers {
val p1 = Process("perl", List("-e", """my $str=<>; print STDERR Hello; print STDOUT "$str""""))
val p2 = Process("sort")
val p3 = Process("wc", List("-w"))
val processGroup = ((p1 | p2 | p3) < stream !># ZTransducer.utf8Decode) ># ZTransducer.utf8Decode
val processGroup = ((p1 | p2 | p3) < stream !># ZPipeline.utf8Decode) ># ZPipeline.utf8Decode

processGroup.run()
.map { result =>
Expand All @@ -418,7 +418,7 @@ object ProcessGroupSpecs extends DefaultRunnableSpec with ProxSpecHelpers {
val p1 = Process("perl", List("-e", """my $str=<>; print STDERR Hello; print STDOUT "$str""""))
val p2 = Process("sort")
val p3 = Process("wc", List("-w"))
val processGroup = ((p1 | p2 | p3) !># ZTransducer.utf8Decode) ># ZTransducer.utf8Decode < stream
val processGroup = ((p1 | p2 | p3) !># ZPipeline.utf8Decode) ># ZPipeline.utf8Decode < stream

processGroup.run()
.map { result =>
Expand All @@ -435,7 +435,7 @@ object ProcessGroupSpecs extends DefaultRunnableSpec with ProxSpecHelpers {
val p1 = Process("perl", List("-e", """my $str=<>; print STDERR Hello; print STDOUT "$str""""))
val p2 = Process("sort")
val p3 = Process("wc", List("-w"))
val processGroup = ((p1 | p2 | p3) !># ZTransducer.utf8Decode) < stream ># ZTransducer.utf8Decode
val processGroup = ((p1 | p2 | p3) !># ZPipeline.utf8Decode) < stream ># ZPipeline.utf8Decode

processGroup.run()
.map { result =>
Expand All @@ -452,7 +452,7 @@ object ProcessGroupSpecs extends DefaultRunnableSpec with ProxSpecHelpers {
val p1 = Process("perl", List("-e", """my $str=<>; print STDERR Hello; print STDOUT "$str""""))
val p2 = Process("sort")
val p3 = Process("wc", List("-w"))
val processGroup = ((p1 | p2 | p3) ># ZTransducer.utf8Decode) < stream !># ZTransducer.utf8Decode
val processGroup = ((p1 | p2 | p3) ># ZPipeline.utf8Decode) < stream !># ZPipeline.utf8Decode

processGroup.run()
.map { result =>
Expand All @@ -469,7 +469,7 @@ object ProcessGroupSpecs extends DefaultRunnableSpec with ProxSpecHelpers {
val p1 = Process("perl", List("-e", """my $str=<>; print STDERR Hello; print STDOUT "$str""""))
val p2 = Process("sort")
val p3 = Process("wc", List("-w"))
val processGroup = (((p1 | p2 | p3) ># ZTransducer.utf8Decode) !># ZTransducer.utf8Decode) < stream
val processGroup = (((p1 | p2 | p3) ># ZPipeline.utf8Decode) !># ZPipeline.utf8Decode) < stream

processGroup.run()
.map { result =>
Expand All @@ -483,7 +483,7 @@ object ProcessGroupSpecs extends DefaultRunnableSpec with ProxSpecHelpers {

test("bound process is not pipeable") {
assertM(
typeCheck("""val bad = (Process("echo", List("Hello world")) ># ZTransducer.utf8Decode) | Process("wc", List("-w"))"""))(
typeCheck("""val bad = (Process("echo", List("Hello world")) ># ZPipeline.utf8Decode) | Process("wc", List("-w"))"""))(
isLeft(anything)
)
}
Expand Down
Loading

0 comments on commit ba39493

Please sign in to comment.