Skip to content

Commit

Permalink
Upgrade to ZIO 2.0.0-RC2 (#465)
Browse files Browse the repository at this point in the history
  • Loading branch information
adamgfraser authored Feb 2, 2022
1 parent 84aa783 commit 8969280
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 97 deletions.
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ addCommandAlias(
";zioNio/test;examples/test"
)

val zioVersion = "2.0.0-RC1"
val zioVersion = "2.0.0-RC2"

lazy val zioNio = project
.in(file("nio"))
Expand Down
2 changes: 1 addition & 1 deletion examples/src/main/scala/ToUppercaseAsAService.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import scala.util.control.Exception._
object ToUppercaseAsAService extends ZIOAppDefault {

private val upperCaseIfier: ZPipeline[Any, Nothing, Char, Char] =
ZPipeline.identity[Char] >>> ZPipeline.map(_.toUpper)
ZPipeline.identity[Char] >>> ZPipeline.map[Char, Char](_.toUpper)

private def handleConnection(
socket: SocketChannel
Expand Down
2 changes: 1 addition & 1 deletion nio/src/main/scala/zio/nio/channels/GatheringByteOps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package zio.nio.channels

import zio._
import zio.nio.Buffer.byteFromJava
import zio.nio.{Buffer, ByteBuffer, ZSinkCompanionOps}
import zio.nio.{Buffer, ByteBuffer}
import zio.stacktracer.TracingImplicits.disableAutoTrace
import zio.stream.{ZSink, ZStream}

Expand Down
94 changes: 0 additions & 94 deletions nio/src/main/scala/zio/nio/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -69,99 +69,5 @@ package object nio {
f(a).onExit(finalizer).fork
}
}

}

implicit final class ZPipelineCompanionOps(private val pipeline: ZPipeline.type) extends AnyVal {

/**
* Creates a pipeline from a chunk processing function.
*/
/**
* Creates a pipeline from a chunk processing function.
*/
def fromPush[Env, Err, In, Out](
push: => ZManaged[Env, Nothing, Option[Chunk[In]] => ZIO[Env, Err, Chunk[Out]]]
): ZPipeline[Env, Err, In, Out] =
new ZPipeline[Env, Err, In, Out] {
def apply[Env1 <: Env, Err1 >: Err](stream: ZStream[Env1, Err1, In])(implicit
trace: ZTraceElement
): ZStream[Env1, Err1, Out] = {

def pull(
push: Option[Chunk[In]] => ZIO[Env, Err, Chunk[Out]]
): ZChannel[Env, Nothing, Chunk[In], Any, Err, Chunk[Out], Any] =
ZChannel.readWith[Env, Nothing, Chunk[In], Any, Err, Chunk[Out], Any](
in =>
ZChannel
.fromZIO(push(Some(in)))
.flatMap(out => ZChannel.write(out))
.zipRight[Env, Nothing, Chunk[In], Any, Err, Chunk[Out], Any](pull(push)),
err => ZChannel.fail(err),
_ => ZChannel.fromZIO(push(None)).flatMap(out => ZChannel.write(out))
)

val channel: ZChannel[Env, Nothing, Chunk[In], Any, Err, Chunk[Out], Any] =
ZChannel.unwrapManaged[Env, Nothing, Chunk[In], Any, Err, Chunk[Out], Any] {
push.map(pull)
}

stream.pipeThroughChannelOrFail(channel)
}
}
}

implicit final class ZSinkCompanionOps(private val sink: ZSink.type) {

/**
* Creates a sink from a chunk processing function.
*/
def fromPush[R, E, I, L, Z](
push: ZManaged[R, Nothing, Option[Chunk[I]] => ZIO[R, (Either[E, Z], Chunk[L]), Unit]]
)(implicit trace: ZTraceElement): ZSink[R, E, I, L, Z] = {

def pull(
push: Option[Chunk[I]] => ZIO[R, (Either[E, Z], Chunk[L]), Unit]
): ZChannel[R, Nothing, Chunk[I], Any, E, Chunk[L], Z] =
ZChannel.readWith[R, Nothing, Chunk[I], Any, E, Chunk[L], Z](
in =>
ZChannel
.fromZIO(push(Some(in)))
.foldChannel[R, Nothing, Chunk[I], Any, E, Chunk[L], Z](
{
case (Left(e), leftovers) =>
ZChannel.write(leftovers).zipRight[R, Nothing, Chunk[I], Any, E, Chunk[L], Z](ZChannel.fail(e))
case (Right(z), leftovers) =>
ZChannel
.write(leftovers)
.zipRight[R, Nothing, Chunk[I], Any, E, Chunk[L], Z](ZChannel.succeedNow(z))
},
_ => pull(push)
),
err => ZChannel.fail(err),
_ =>
ZChannel
.fromZIO(push(None))
.foldChannel[R, Nothing, Chunk[I], Any, E, Chunk[L], Z](
{
case (Left(e), leftovers) =>
ZChannel.write(leftovers).zipRight[R, Nothing, Chunk[I], Any, E, Chunk[L], Z](ZChannel.fail(e))
case (Right(z), leftovers) =>
ZChannel
.write(leftovers)
.zipRight[R, Nothing, Chunk[I], Any, E, Chunk[L], Z](ZChannel.succeedNow(z))
},
_ => ZChannel.fromZIO(ZIO.dieMessage("empty sink"))
)
)

new ZSink(
ZChannel.unwrapManaged[R, Nothing, Chunk[I], Any, E, Chunk[L], Z] {
push.map(pull)
}
)
}

}

}

0 comments on commit 8969280

Please sign in to comment.