Given a List, I'd like to filter out any elements that equal Unit - ().
Is there a better way to filter than through this code?
scala> List( () ).filter( x => x != () )
<console>:8: warning: comparing values of types Unit and Unit using `!=' will
always yield false
List( () ).filter( x => x != () )
^
res10: List[Unit] = List()
I'd go with this:
List(1, (), 4, (), 9, (), 16) filter (_ != ())
res0: List[AnyVal] = List(1, 4, 9, 16)
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