Question about some of the documentation in akka streams

In working with graphs you have an example of a partial graph that doesn’t make a ton of sense to me.

val pickMaxOfThree = GraphDSL.create() { implicit b ⇒
  import GraphDSL.Implicits._

  val zip1 = b.add(ZipWith[Int, Int, Int](math.max _))
  val zip2 = b.add(ZipWith[Int, Int, Int](math.max _))
  zip1.out ~> zip2.in0

  UniformFanInShape(zip2.out, zip1.in0, zip1.in1, zip2.in1)
}

wouldn’t zip1.in2 and zip2.in2 be unbound in this example? and why are two ZipWiths needed at all, wouldn’t the first pick the max of the three inputs already?

Those ZipWiths are look like this: ZipWith[In0, In1, Out](f: (In0, In1) => Out)

So they don’t have in3.

The graph looks like this:

UniformIn1+-------+
                 zip1+--+
UniformIn2+-------+     +
                       zip2+----+UniformOut
UniformIn3+-------------+

Ah ok. But you could just have a ZipWith[Int,Int,Int,Int]{ case (i0,i1,i2) => math.max(math.max(i0,i1),i2) } right?

Yes, ZipWith has generated versions for many inputs – though the purpose of that specific example is more to teach about how to combine things in the advanced graph DSL and the predefined shapes rather than showing ZipWith specifically – but yeah, you’re absolutely right.

It could be a good @@@ note to add on that docs section, would you PR such addition @tg44?
The file is here https://github.com/johanandren/akka/blob/master/akka-docs/src/main/paradox/stream/stream-graphs.md

Yapp! Today I found another “not so clear” part of the docs too, I will fix that too!

2 Likes

Awesome, thanks a lot :slight_smile:

Thanks for asking this question. I was confused about the same example, and the drawing our made @tg44 helped a lot! Is there a way to add such drawings to the documentation?

We would want nice diagrams but we have yet to decide how, there is an issue discussing how we can add nice diagrams without it becoming too work intense to maintain/get to work here: https://github.com/akka/akka/issues/24933

2 Likes

Thanks @johanandren!