在Seq上映射以过滤

时间:2014-03-04 14:16:36

标签: scala

我有一个Seq [Document]。

Document有一个val字段,这是一个String,可以做

d.typ   ---> which will be a String

我想映射并过滤Seq以生成一个新的Seq,只有那些typ字段等于特定字符串的Documents。到目前为止,我有这个:

def getNewProducts(docs: Seq[Document]):Seq[Document] = {

   docs.map(_.typ == "new-product")

}

我知道我需要为map函数提供谓词过滤器,而不是如何操作。感谢所有感谢。

1 个答案:

答案 0 :(得分:1)

寻找这个?

docs.filter(_.typ == "new-product")
相关问题