Mandroid
Mandroid

Reputation: 7468

scala: for comprehension with Option

I have an Option of a Seq of some items:

Option[Seq[MyItem]]

MyItem has a field 'description'

I need to find whether one of the items has a specific description.

How can it be done using for comprehension?

Upvotes: 0

Views: 161

Answers (1)

Tim
Tim

Reputation: 27356

If you want to test whether any element of Option[Seq[MyItem]] has a specific description then you can do this.

opt.exists(_.exists(_.description == ???))

If you really need a solution that uses for then I can't help you :)

Upvotes: 2

Related Questions