=str - fixing TODO about scaladsl & javadsl Source/Sink/Flow/BidiFlow.wrap not having to needlessly re-wrap

This commit is contained in:
Viktor Klang 2015-06-06 17:17:23 +02:00
parent 8527e0347e
commit 3bf1c14b3a
8 changed files with 41 additions and 9 deletions

View file

@ -17,7 +17,11 @@ object BidiFlow {
* A graph with the shape of a BidiFlow logically is a BidiFlow, this method makes * A graph with the shape of a BidiFlow logically is a BidiFlow, this method makes
* it so also in type. * it so also in type.
*/ */
def wrap[I1, O1, I2, O2, M](g: Graph[BidiShape[I1, O1, I2, O2], M]): BidiFlow[I1, O1, I2, O2, M] = new BidiFlow(scaladsl.BidiFlow.wrap(g)) def wrap[I1, O1, I2, O2, M](g: Graph[BidiShape[I1, O1, I2, O2], M]): BidiFlow[I1, O1, I2, O2, M] =
g match {
case bidi: BidiFlow[I1, O1, I2, O2, M] bidi
case other new BidiFlow(scaladsl.BidiFlow.wrap(other))
}
/** /**
* Create a BidiFlow where the top and bottom flows are just one simple mapping * Create a BidiFlow where the top and bottom flows are just one simple mapping

View file

@ -39,7 +39,11 @@ object Flow {
* A graph with the shape of a flow logically is a flow, this method makes * A graph with the shape of a flow logically is a flow, this method makes
* it so also in type. * it so also in type.
*/ */
def wrap[I, O, M](g: Graph[FlowShape[I, O], M]): Flow[I, O, M] = new Flow(scaladsl.Flow.wrap(g)) def wrap[I, O, M](g: Graph[FlowShape[I, O], M]): Flow[I, O, M] =
g match {
case f: Flow[I, O, M] f
case other new Flow(scaladsl.Flow.wrap(other))
}
/** /**
* Helper to create `Flow` from a pair of sink and source. * Helper to create `Flow` from a pair of sink and source.

View file

@ -118,7 +118,11 @@ object Sink {
* A graph with the shape of a sink logically is a sink, this method makes * A graph with the shape of a sink logically is a sink, this method makes
* it so also in type. * it so also in type.
*/ */
def wrap[T, M](g: Graph[SinkShape[T], M]): Sink[T, M] = new Sink(scaladsl.Sink.wrap(g)) def wrap[T, M](g: Graph[SinkShape[T], M]): Sink[T, M] =
g match {
case s: Sink[T, M] s
case other new Sink(scaladsl.Sink.wrap(other))
}
} }
/** /**

View file

@ -112,7 +112,9 @@ object Source {
// but there is not anything we can do to prevent that from happening. // but there is not anything we can do to prevent that from happening.
// ConcurrentModificationException will be thrown in some cases. // ConcurrentModificationException will be thrown in some cases.
val scalaIterable = new immutable.Iterable[O] { val scalaIterable = new immutable.Iterable[O] {
import collection.JavaConverters._ import collection.JavaConverters._
override def iterator: Iterator[O] = iterable.iterator().asScala override def iterator: Iterator[O] = iterable.iterator().asScala
} }
new Source(scaladsl.Source(scalaIterable)) new Source(scaladsl.Source(scalaIterable))
@ -215,7 +217,11 @@ object Source {
* A graph with the shape of a source logically is a source, this method makes * A graph with the shape of a source logically is a source, this method makes
* it so also in type. * it so also in type.
*/ */
def wrap[T, M](g: Graph[SourceShape[T], M]): Source[T, M] = new Source(scaladsl.Source.wrap(g)) def wrap[T, M](g: Graph[SourceShape[T], M]): Source[T, M] =
g match {
case s: Source[T, M] s
case other new Source(scaladsl.Source.wrap(other))
}
} }
/** /**

View file

@ -130,7 +130,11 @@ object BidiFlow extends BidiFlowApply {
* A graph with the shape of a flow logically is a flow, this method makes * A graph with the shape of a flow logically is a flow, this method makes
* it so also in type. * it so also in type.
*/ */
def wrap[I1, O1, I2, O2, Mat](graph: Graph[BidiShape[I1, O1, I2, O2], Mat]): BidiFlow[I1, O1, I2, O2, Mat] = new BidiFlow(graph.module) def wrap[I1, O1, I2, O2, Mat](graph: Graph[BidiShape[I1, O1, I2, O2], Mat]): BidiFlow[I1, O1, I2, O2, Mat] =
graph match {
case bidi: BidiFlow[I1, O1, I2, O2, Mat] bidi
case other new BidiFlow(other.module)
}
/** /**
* Create a BidiFlow where the top and bottom flows are just one simple mapping * Create a BidiFlow where the top and bottom flows are just one simple mapping

View file

@ -302,7 +302,11 @@ object Flow extends FlowApply {
* A graph with the shape of a flow logically is a flow, this method makes * A graph with the shape of a flow logically is a flow, this method makes
* it so also in type. * it so also in type.
*/ */
def wrap[I, O, M](g: Graph[FlowShape[I, O], M]): Flow[I, O, M] = new Flow(g.module) def wrap[I, O, M](g: Graph[FlowShape[I, O], M]): Flow[I, O, M] =
g match {
case f: Flow[I, O, M] f
case other new Flow(other.module)
}
/** /**
* Helper to create `Flow` from a pair of sink and source. * Helper to create `Flow` from a pair of sink and source.

View file

@ -58,7 +58,11 @@ object Sink extends SinkApply {
* A graph with the shape of a sink logically is a sink, this method makes * A graph with the shape of a sink logically is a sink, this method makes
* it so also in type. * it so also in type.
*/ */
def wrap[T, M](g: Graph[SinkShape[T], M]): Sink[T, M] = new Sink(g.module) def wrap[T, M](g: Graph[SinkShape[T], M]): Sink[T, M] =
g match {
case s: Sink[T, M] s
case other new Sink(other.module)
}
/** /**
* Helper to create [[Sink]] from `Subscriber`. * Helper to create [[Sink]] from `Subscriber`.

View file

@ -202,8 +202,10 @@ object Source extends SourceApply {
* A graph with the shape of a source logically is a source, this method makes * A graph with the shape of a source logically is a source, this method makes
* it so also in type. * it so also in type.
*/ */
// TODO optimize if no wrapping needed def wrap[T, M](g: Graph[SourceShape[T], M]): Source[T, M] = g match {
def wrap[T, M](g: Graph[SourceShape[T], M]): Source[T, M] = new Source(g.module) case s: Source[T, M] s
case other new Source(other.module)
}
/** /**
* Helper to create [[Source]] from `Iterable`. * Helper to create [[Source]] from `Iterable`.