Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Concise way in Scala to combine filterNot/match/case

Tags:

scala

I need to filter a sequence to remove an element that matches a certain case.

This seems too clumsy:

val filtered = 
   headers.filterNot{ case Authorization(_) => true; case _ => false }

Is there a more concise/idiomatic way?

like image 760
Thilo Avatar asked Mar 14 '23 06:03

Thilo


1 Answers

You can use isInstanceOf, like this

headers.filterNot(_.isInstanceOf[Authorization])
like image 184
thefourtheye Avatar answered Mar 24 '23 04:03

thefourtheye