我试图将外部地图添加到现有地图,但仍然从该方法返回相同的内容。
这是现有地图的外观:
def someMethod(checkType: String) : Flow[ByteString, MyClass[OtherClass], NotUsed] = {
someFlow
.map (s => SomeParser(s))
.collect {
case Right(ts) => ts
}
.map {t =>
val somedata = checkType match {
case "foo" => SomeClass.someMethod(t)
}
(one, two)
}
.map {x =>
x._2.leftMap(xs => {
someMethod(x._1, xs.toList)
}).toEither
}
}
我正在尝试添加外部地图,但仍然能够返回上述方法中从原始地图返回的内容。我在下面尝试过,但是这样做scala抱怨返回不匹配。为了便于识别,我评论了以下几行。
def someMethod(checkType: String) : Flow[ByteString, MyClass[OtherClass], NotUsed] = {
anotherFlow.map {l => //new
someFlow
.map (s => SomeParser(s))
.collect {
case Right(ts) => ts
}
.map {t =>
val myClass = MyCaseClass(t, l) //new
val somedata = checkType match {
case "foo" => SomeClass.someMethod(myClass.t) //modified
}
(one, two)
}
.map {x =>
x._2.leftMap(xs => {
someMethod(x._1, xs.toList)
}).toEither
}
}
}