Scala, How to traverse through sequence -


i have seq[object] , want iterate through each object , check if 1 of boolean properties true/false. i've tried use flatmap followed filter it's not working:

val systemresourcesexpandable = host.systemresources flatmap (.child) filter { childseq =>     {        child <- childseq;        child.config flatmap (.cpuallocation) flatmap (_.expandablereservation)     } yield { child }  } 

assuming object following

case class myobject(intprop: int, boolprop: boolean) 

and sequence this

val mysequence = seq(obj1, obj2, obj3) 

you use following logic filter out false boolean conditions on boolprop

mysequence.filter(x => x.boolprop) 

this operation return new sequence objects have boolprop of true. note, not modify sequence, instead returns new one.


Comments