Scala: How to avoid check instance and casting -
i found myself in condition of running:
somecollection.filter(_.isinstanceof[foo]).asinstanceof[list[foo]]
just check if collection has instances of foo
, casting final filtered collection.
is there better way (assuming cannot change current data structure)?
i tried with:
somecollection.map(case c: foo => c)
but @ runtime returns matchingerror
of course looking remaining cases (case _ =>
).
somecollection.collect { case c: foo => c }
Comments
Post a Comment