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

Skip to content
Merged
Show file tree
Hide file tree
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
4 changes: 1 addition & 3 deletions benchmarks/src/main/scala-2.12/zio/GenBenchmarks.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,14 @@ class GenBenchmarks {
var elementSize: Int = _
@Benchmark
def zioDouble: List[Double] =
unsafeRun(Gen.listOfN(listSize)(Gen.uniform).sample.collectSome.map(_.value).runHead.some)
unsafeRun(Gen.listOfN(listSize)(Gen.uniform).sample.map(_.value).runHead.some)

@Benchmark
def zioIntListsOfSizeN: List[List[Int]] =
unsafeRun(
Gen
.listOfN(listSize)(Gen.listOfN(elementSize)(Gen.int))
.sample
.collectSome
.map(_.value)
.runHead
.some
Expand All @@ -40,7 +39,6 @@ class GenBenchmarks {
Gen
.listOfN(listSize)(Gen.stringN(elementSize)(Gen.char))
.sample
.collectSome
.map(_.value)
.runHead
.some
Expand Down
3 changes: 1 addition & 2 deletions benchmarks/src/main/scala/zio/test/GenBenchmark.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,12 @@ class GenBenchmark {

@Setup
def setup(): Unit = {
listOfNEffect = Gen.listOfN(size)(Gen.byte).sample.forever.collectSome.take(count).runDrain
listOfNEffect = Gen.listOfN(size)(Gen.byte).sample.forever.take(count).runDrain
causesEffect = Sized.live(size)(Trace.empty) {
Gen
.causes(Gen.string, Gen.string.map(s => new RuntimeException(s)))
.sample
.forever
.collectSome
.take(count)
.runDrain
}
Expand Down
6 changes: 5 additions & 1 deletion project/MimaSettings.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ object MimaSettings {
exclude[IncompatibleMethTypeProblem]("zio.Config#*"),
exclude[DirectMissingMethodProblem]("zio.Config#*"),
exclude[DirectMissingMethodProblem]("zio.Config.*"),
exclude[MissingTypesProblem]("zio.Config$Secret$")
exclude[MissingTypesProblem]("zio.Config$Secret$"),
exclude[Problem]("zio.stream.internal.*"),
exclude[MissingClassProblem]("zio.stream.ZChannel$ChildExecutorDecision*"),
exclude[MissingClassProblem]("zio.stream.ZChannel$UpstreamPullRequest*"),
exclude[MissingClassProblem]("zio.stream.ZChannel$UpstreamPullStrategy*")
),
mimaFailOnProblem := failOnProblem
)
Expand Down
84 changes: 0 additions & 84 deletions streams-tests/shared/src/test/scala/zio/stream/ZChannelSpec.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package zio.stream

import zio._
import zio.stream.ZChannel.{ChildExecutorDecision, UpstreamPullRequest, UpstreamPullStrategy}
import zio.test._
import zio.test.Assertion._
import zio.test.TestAspect.{jvmOnly, timeout}
Expand Down Expand Up @@ -282,89 +281,6 @@ object ZChannelSpec extends ZIOBaseSpec {
.concatMapWith(i => ZChannel.write(i).as(List(s"Inner-$i")))(_ ++ _, (_, _))
.runCollect
)(equalTo((Chunk(1, 2, 3), (List("Inner-1", "Inner-2", "Inner-3"), List("Outer-0")))))
},
test("custom 1") {
assertZIO(
ZChannel
.writeAll(1, 2, 3, 4)
.concatMapWithCustom(x =>
ZChannel.writeAll(Some((x, 1)), None, Some((x, 2)), None, Some((x, 3)), None, Some((x, 4)))
)(
(_, _) => (),
(_, _) => (),
{
case UpstreamPullRequest.Pulled(_) => UpstreamPullStrategy.PullAfterNext(None)
case UpstreamPullRequest.NoUpstream(_) => UpstreamPullStrategy.PullAfterAllEnqueued(None)
},
{
case None => ChildExecutorDecision.Yield
case Some(_) => ChildExecutorDecision.Continue
}
)
.runCollect
.map(_._1.flatten)
)(
equalTo(
Chunk(
(1, 1),
(2, 1),
(3, 1),
(4, 1),
(1, 2),
(2, 2),
(3, 2),
(4, 2),
(1, 3),
(2, 3),
(3, 3),
(4, 3),
(1, 4),
(2, 4),
(3, 4),
(4, 4)
)
)
)
},
test("custom 2") {
assertZIO(
ZChannel
.writeAll(1, 2, 3, 4)
.concatMapWithCustom(x =>
ZChannel.writeAll(Some((x, 1)), None, Some((x, 2)), None, Some((x, 3)), None, Some((x, 4)))
)(
(_, _) => (),
(_, _) => (),
_ => UpstreamPullStrategy.PullAfterAllEnqueued(None),
{
case None => ChildExecutorDecision.Yield
case Some(_) => ChildExecutorDecision.Continue
}
)
.runCollect
.map(_._1.flatten)
)(
equalTo(
Chunk(
(1, 1),
(2, 1),
(1, 2),
(3, 1),
(2, 2),
(1, 3),
(4, 1),
(3, 2),
(2, 3),
(1, 4),
(4, 2),
(3, 3),
(2, 4),
(4, 3),
(3, 4),
(4, 4)
)
)
)
}
),
suite("ZChannel#scoped")(
Expand Down
66 changes: 0 additions & 66 deletions streams/shared/src/main/scala/zio/stream/ZChannel.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import zio.{ZIO, _}
import zio.stacktracer.TracingImplicits.disableAutoTrace
import zio.stream.internal.{AsyncInputConsumer, AsyncInputProducer, ChannelExecutor, SingleProducerAsyncInput}
import ChannelExecutor.ChannelState
import zio.stream.ZChannel.{ChildExecutorDecision, UpstreamPullRequest, UpstreamPullStrategy}

/**
* A `ZChannel[Env, InErr, InElem, InDone, OutErr, OutElem, OutDone]` is a nexus
Expand Down Expand Up @@ -194,39 +193,10 @@ sealed trait ZChannel[-Env, -InErr, -InElem, -InDone, +OutErr, +OutElem, +OutDon
ZChannel.ConcatAll(
g,
h,
(_: UpstreamPullRequest[OutElem]) => UpstreamPullStrategy.PullAfterNext(None),
(_: OutElem2) => ChildExecutorDecision.Continue,
() => self,
f
)

/**
* Returns a new channel whose outputs are fed to the specified factory
* function, which creates new channels in response. These new channels are
* sequentially concatenated together, and all their outputs appear as outputs
* of the newly returned channel. The provided merging function is used to
* merge the terminal values of all channels into the single terminal value of
* the returned channel.
*/
private[zio] final def concatMapWithCustom[
Env1 <: Env,
InErr1 <: InErr,
InElem1 <: InElem,
InDone1 <: InDone,
OutErr1 >: OutErr,
OutElem2,
OutDone2,
OutDone3
](
f: OutElem => ZChannel[Env1, InErr1, InElem1, InDone1, OutErr1, OutElem2, OutDone2]
)(
g: (OutDone2, OutDone2) => OutDone2,
h: (OutDone2, OutDone) => OutDone3,
onPull: UpstreamPullRequest[OutElem] => UpstreamPullStrategy[OutElem2],
onEmit: OutElem2 => ChildExecutorDecision
)(implicit trace: Trace): ZChannel[Env1, InErr1, InElem1, InDone1, OutErr1, OutElem2, OutDone3] =
ZChannel.ConcatAll(g, h, onPull, onEmit, () => self, f)

/**
* Returns a new channel, which is the same as this one, except its outputs
* are filtered and transformed by the specified partial function.
Expand Down Expand Up @@ -1362,8 +1332,6 @@ object ZChannel {
](
combineInners: (OutDone, OutDone) => OutDone,
combineAll: (OutDone, OutDone2) => OutDone3,
onPull: UpstreamPullRequest[OutElem] => UpstreamPullStrategy[OutElem2],
onEmit: OutElem2 => ChildExecutorDecision,
value: () => ZChannel[Env, InErr, InElem, InDone, OutErr, OutElem, OutDone2],
k: OutElem => ZChannel[Env, InErr, InElem, InDone, OutErr, OutElem2, OutDone]
) extends ZChannel[Env, InErr, InElem, InDone, OutErr, OutElem2, OutDone3]
Expand Down Expand Up @@ -1520,9 +1488,6 @@ object ZChannel {
ConcatAll(
f,
g,
(_: UpstreamPullRequest[ZChannel[Env, InErr, InElem, InDone, OutErr, OutElem, OutDone]]) =>
UpstreamPullStrategy.PullAfterNext(None),
(_: OutElem) => ChildExecutorDecision.Continue,
() => channels,
(channel: ZChannel[Env, InErr, InElem, InDone, OutErr, OutElem, OutDone]) => channel
)
Expand Down Expand Up @@ -1973,37 +1938,6 @@ object ZChannel {
case object BufferSliding extends MergeStrategy
}

private[zio] sealed trait ChildExecutorDecision
private[zio] object ChildExecutorDecision {

/** Continue executing the current substream */
case object Continue extends ChildExecutorDecision

/**
* Close the current substream with a given value and pass execution to the
* next substream
*/
final case class Close(value: Any) extends ChildExecutorDecision

/**
* Pass execution to the next substream. This either pulls a new element
* from upstream, or yields to an already created active substream.
*/
case object Yield extends ChildExecutorDecision
}

private[zio] sealed trait UpstreamPullRequest[+A]
private[zio] object UpstreamPullRequest {
final case class Pulled[+A](value: A) extends UpstreamPullRequest[A]
final case class NoUpstream(activeDownstreamCount: Int) extends UpstreamPullRequest[Nothing]
}

private[zio] sealed trait UpstreamPullStrategy[+A]
private[zio] object UpstreamPullStrategy {
final case class PullAfterNext[+A](emitSeparator: Option[A]) extends UpstreamPullStrategy[A]
final case class PullAfterAllEnqueued[+A](emitSeparator: Option[A]) extends UpstreamPullStrategy[A]
}

final class EnvironmentWithPartiallyApplied[Env](private val dummy: Boolean = true) extends AnyVal {
def apply[OutDone](f: ZEnvironment[Env] => OutDone)(implicit
trace: Trace
Expand Down
Loading