I have the following variable series
:
var series: List[FlotSerie] = List(
new FlotSerie() {
override val label = Full("Min")
},
new FlotSerie() {
override val label = Full("Max")
},
new FlotSerie() {
override val label = Full("Avg")
}
)
Unfortunately, I am getting a compiler error with the following method, which takes a new data point and updates series
with a new List[FlotSeries]
based upon the new data and the old series.
def updateSeries(sample: Sample): List[FlotSerie] = {
series = series.map(serie =>
serie match {
case item if item.label == Full("Min") => {
new FlotSerie() {
override val label = item.label
override val data = (sample.timestamp.toDouble, sample.min) :: serie.data
}
}
case item if item.label == Full("Max") => {
new FlotSerie() {
override val label = item.label
override val data = (sample.timestamp.toDouble, sample.max) :: serie.data
}
}
case item if item.label == Full("Avg") => {
new FlotSerie() {
override val label = item.label
override val data = (sample.timestamp.toDouble, sample.avg) :: serie.data
}
}
}
)
}
The Scala compiler chokes on the reassignment because it finds a type mismatch:
error: type mismatch;
found : Unit
required: List[net.liftweb.widgets.flot.FlotSerie]
series = series.map(serie => serie match {
What am I doing wrong here? It seems like it should be returning a List[FlotSeries] that can be assigned to series
. Since the compiler finds Unit
I thought of how foreach
always returns Unit
, I am but the match
operator returns the last value of the matched expression, not Unit
.