Is there a better way to write this block of code? In particular is it possible to factor the conversion in a external function?
nodes collect { case x: InstrumentSource[_] if (x.m <:< implicitly[ClassManifest[BarClose]]) => x.asInstanceOf[InstrumentSource[BarClose]] };
m in InstrumentSource is a class manifest:
case class InstrumentSource[A](implicit val m: ClassManifest[A])
and nodes is a collection of various InstrumentSource.
My idea is:
(Renamed InstrumentSource to InstSource for not scrolling here)
So the price is defining
HasClassManifestand<-<once and every class you want to patternmatch on has to extendHasClassManifest. That´s all.But I don´t know how to factor out the
instanceOfconversion on the right hand side at the moment.