I have two sequences, i.e. prices: Seq[Price]
and overrides: Seq[Override]
. I need to do some magic on them yet only for a subset based on a shared id.
So I grouped them both into a Map
each via groupBy
:
I do the group by via:
val pricesById = prices.groupBy(_.someId) // Int => Seq[Cruise]
val overridesById = overrides.groupBy(_.someId) // // Int => Seq[Override]
I expected to be able to create my wanted sequence via flatMap
:
val applyOverrides = (someId: Int, prices: Seq[Price]): Seq[Price] => {
val applicableOverrides = overridesById.getOrElse(someId, Seq())
magicMethod(prices, applicableOverrides) // returns Seq[Price]
}
val myPrices: Seq[Price] = pricesById.flatMap(applyOverrides)
I expected myPrices
to contain just one big Seq[Price]
.
Yet I get a weird type mismatch within the flatMap method with NonInferedB I am unable to resolve.