3
我使用ReactiveMongo用MongoDB的一个游戏框架应用程序,我有以下代码:创作期货与理解力
def categories(id: String): Future[Vector[Category]] = {...}
....
val categoriesFuture = categories(id)
for {
categories: Vector[Category] <- categoriesFuture
categoryIdsWithoutPerson: Vector[BSONObjectID] <- findCategoryIdsWithoutPerson(categories.map(_.id), personId) //Returns Future[Vector[BSONObjectID]]
categoriesWithoutPerson: Vector[Category] <- categories.filter(category => categoryIdsWithoutPerson.contains(category.id)) //Play cites the error here
} yield categoryIdsWithoutPerson
为了解释这个代码,我取包裹的Categories
一个Vector
在Future
,因为这是ReactiveMongo如何滚动。在for
的理解中,我使用Vector
来从数据库中获取一个id列表。最后,我使用一个filter
调用来仅保留那些可以在该id列表中找到id的类别。
这一切似乎相当简单。问题是,游戏给了我下面的编译错误的for
理解的最后一行:
pattern type is incompatible with expected type;
found : Vector[com.myapp.Category]
required: com.myapp.Category
我不知道为什么所需的类型是Category
一个实例。
我可以使用一些洞察力来了解我在做什么错误和/或是否有更简单或更习惯的方式来完成此操作。
你可以张贴的 '类别' 方法的签名?以及在哪一行检测到错误? – ale64bit 2014-11-23 21:47:31
按要求澄清。谢谢。 – Vidya 2014-11-23 21:59:15
只是好奇,为什么你产生categoryIdsWithoutPerson为结果?什么是理解的最后一行? – ale64bit 2014-11-23 22:02:28