Reputation: 3812
I have the following filter on a List:
messages = messages.filterNot(m => m.room == room)
What I'm trying to do is have multiple arguments so I can match all items that have the same room ID and the same data value, so something like:
messages = messages.filterNot(m => m.room == room, m.data == data)
This doesnt work of course, is there a way I can do this?
Thanks in advance, any help much appreciated :)
Upvotes: 3
Views: 5435
Reputation: 10776
You can deal with it
straightforward
messages.filterNot(m => m.room == room && m.data == data)
chaining filters
messages.filterNot(_.room == room).filterNot(_.data == data)
using WithFilter which applies restrictions on original collection instead of creating intermediate ones
messages.withFilter(_.room != room).withFilter(_.data != data) map identity
Upvotes: 12