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

Popular posts from this blog

unity3d - Rotate an object to face an opposite direction -

angular - Is it possible to get native element for formControl? -

javascript - Why jQuery Select box change event is now working? -