jahilldev
jahilldev

Reputation: 3812

scala lift - filterNot with multiple arguments

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

Answers (1)

4e6
4e6

Reputation: 10776

You can deal with it

  1. straightforward

    messages.filterNot(m => m.room == room && m.data == data)
  2. chaining filters

    messages.filterNot(_.room == room).filterNot(_.data == data)
  3. using WithFilter which applies restrictions on original collection instead of creating intermediate ones

    messages.withFilter(_.room != room).withFilter(_.data != data) map identity

Upvotes: 12

Related Questions