temp1 <- Future.sequence(file.map { ref =>
readFile(ref, config).map { (ref, _) }
}).map(f => f.filter(parsed => parsed._2.errors.nonEmpty))
temp2 <- Future.sequence(file.map { ref =>
readFile(ref, config).map { (ref, _) }
})
我不想调用 readFile 方法 2 次。如何仅调用一次并按照过滤器将输出保存在 temp1 和 temp2 中。
如果我正确理解您的代码,您希望temp1
并且temp2
包含类似的数据,但是temp2
您还调用map(...)
那么为什么您不能先创建temp2
然后以这种方式设置temp1 = temp2.map(f => f.filter(parsed => parsed._2.errors.nonEmpty))
您只会调用一次 readFile。还是我错过了什么?