filter if some property value is in list of defined data
Given data and filterList,
scala> case class Customer(name: String, preference: Option[String])
defined class Customer
scala> Seq(Customer("prayagupd", Some("music")), Customer("stevenwilson", Some("soccer")))
res3: Seq[Customer] = List(Customer(prayagupd,Some(music)), Customer(stevenwilson,Some(soccer)))
scala> val filterPrefs = Seq("music", "reading")
filterPrefs: Seq[String] = List(music, reading)
Apply the filter,
scala> res3.filter(c => filterPrefs.exists(p => c.preference.contains(p)))
res16: Seq[Customer] = List(Customer(prayagupd,Some(music)))
Written by Prayag Upd
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Scala
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#