Source.combine 不接受可变参数?

Source.combine doesn't take varargs?

Akka 是否试图传达 Source.combine 不应与资源集合一起使用?还是我对函数定义有点笨?

Akka Source.combine 在 vararags 之前需要第一个和第二个源。函数定义如下:

def combine[T, U](first: Source[T, _], second: Source[T, _], rest: Source[T, _]*)(
      strategy: Int => Graph[UniformFanInShape[T, U], NotUsed]

我只想做类似的事情:

val sources : Seq[Source[Int,_]] = ???
Source.combine(sources:_*)(Merge(_))

我不知道我的 sources 是否会有 1,2 个或多个来源。所以写案例会增加几行。没什么大不了的,但我觉得我错过了什么。这是 akka 流的反模式吗?

模式 first: Source[T, _], second: Source[T, _], rest: Source[T, _]* 的要点是确保您将至少 2 个(可能更多)源传递给方法。

如果允许方法签名sources:_*,您可以传递空的可变参数或仅传递单个元素。

在你的例子中,如果 sources 是 Seq,我将只对 sources 进行模式匹配以拆分为第一个和第二个元素以及其余元素:

sources match {
   case first :: second :: rest => Source.combine(first, second, rest:_*)(Merge(_))
   case _ => ??? // too few elements, maybe return Source.failed?
}