I have a Scala sequence which is of format ("Apple-fruit", "Banana-fruittoo", "Chocolate-notafruit") and I have another Scala list of format ("Apple", "Banana")
I want to filter my first sequence based on second list so that my final output is ("Apple-fruit", "Banana-fruittoo"). Could anyone help me with this filter function?
Seq("Apple-fruit", "Banana-fruittoo", "Chocolate-notafruit")
.filter(x => Seq("Apple", "Banana").exists(y => x.contains(y)))
// Seq("Apple-fruit", "Banana-fruittoo")
For each item (x) of the seq to filter, we check if at least one element (y) of the filtering seq exists such as x contains y.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With