我有以下代码:
override def factors: Source[MarketFactors, NotUsed] = {
Source(Stream.continually(generator)).map(random => {
val correlated = currentFactors.keys zip random.nextVector()
val generatedPrice: Map[Equity, Double] = correlated.toSeq.map({
case (equity, randomValue) =>
(equity, currentFactors(equity).price + randomValue * currentFactors(equity).volatility)
})(scala.collection.breakOut)
GeneratedMarketFactors(generatedPrice)
})
}
它应该从随机生成器获取值并创建新价格。
给map的函数的类型为CorrelatedRandomVectorGenerator => MarketFactors
。 GeneratedMarketFactors
被声明为内部案例类并扩展MarketFactors
。
但是,我收到错误Expression of type FactorsGenerator.GeneratedMarketFactors doesn't conform to expected type T_
。我做错了什么?
我对Scala和Akka流之间的混合感到不满意,是Stream.continually(generator)
的替换吗?