NamedMap, extract ports from map of instances
Issue #21
resolved
With earlier Record notation i would:
val segment=Record[SegmentSeeded]("segment")
for ( i <- 1 to 3) {
segment(i)=SegmentSeeded(in= .... ,
parameters....)
}
val segment_mask=Array2Folder(rec2Array(segment,"mask") , fileMode=".")
val segment_perimeter=Array2Folder(rec2Array(segment,"perimeter") , fileMode=".")
The above would pick the Record of component instances "segment" and find the output port "mask" from each of them, and create an array of those. And then same for "perimeter".
I know it's basically a mapping operation, like this:
makeArray((for ((k,v) <- rec) yield (k,v(portName))).toSeq:_*)
it is such an often used structure - should there be a simplified notation for it?
Comments (3)
-
-
reporter okay, so
val segment_mask=Array2Folder( segment mapValues {_.mask} , fileMode=".")
works then
-
reporter - changed status to resolved
- Log in to comment
Yes. Scala Map supports creating such submaps with mapValues. Here is an example of extracting the attribute String.size.
It's a good idea to read Scaladocs for Map and Seq, they contains lots of useful methods.