Given that Seq.view
returns a SeqView
, I would have expected Set.view
to return a SetView
, but no such view exists; Set.view
instead returns an IterableView
.
Unfortunately, IterableView
is missing some methods, such as contains
. Compare these, for example:
Seq(1, 2, 3).view.map(_ * 2).contains(4) // returns true
Set(1, 2, 3).view.map(_ * 2).contains(4) // error
Is there any particular reason why no SetView
class exists?
Also, is there any reason why Iterable
doesn't have a contains
method (given this is basically a special case of find)?
Given the situation above, is there a better alternative to this when working with sets (in other words, what is the best practice in Scala):
Set(1, 2, 3).view.map(_ * 2).find(_ == 4).isDefined