case class DataItem(name: String, timestamp: Long, value: String)
val dataitems = List(DataItem(SpindleSpeed, 1223334444, 20.3333),
DataItem(SpindleSpeed, 1223334450, 21.3333),
DataItem(SpindleSpeed, 1223334460, 19.3333),
DataItem(Load, 1223334444, 70.0023),
DataItem(Load, 1223334446, 72.0023),
DataItem(Pressure, 1223334444, 20.3333))
I have a list somewhat like this, I need to filter out the dataitems which has the lowest timestamp. There can be more than one dateitems having the same timestamp, in that case I need all those dataitems.
In the above case, I expect the filtered list to be,
List(DataItem(SpindleSpeed, 1223334444, 20.3333),
DataItem(Load, 1223334444, 70.0023),
DataItem(Pressure, 1223334444, 20.3333))
What is the functional way of doing it? I tried sorting the list and returning the head. But that returns only a single dataitem which doesn’t seem to right.
1 Answer