sectornitad
sectornitad

Reputation: 981

Mapping over a Seq to filter

I have a Seq[Document].

Document has a val field which is a String such that one can do

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

I would like to map and filter over the Seq to produce a new Seq of only those Documents whose typ field is equal to a particular string. So far I have this:

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

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

}

I understand that I need to provide a predicate filter to the map function but not how to do it. All thanks gratefully received.

Upvotes: 1

Views: 228

Answers (1)

serejja
serejja

Reputation: 23841

Looking for this?

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

Upvotes: 1

Related Questions