Given that Seq.view returns a SeqView , I would expect Set.view return a SetView , but such a view does not exist; Set.view instead returns an IterableView .
Unfortunately, IterableView lacks some methods, for example, contains . Compare them, 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 special reason why there is no SetView class?
Also, is there any reason why Iterable does not have a contains method (given that this is basically a special case of the search)?
Given the situation above, is there a better alternative to this when working with sets (in other words, which works best for Scala):
Set(1, 2, 3).view.map(_ * 2).find(_ == 4).isDefined
source share