Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8662805
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T16:49:16+00:00 2026-06-12T16:49:16+00:00

case class DataItem(name: String, timestamp: Long, value: String) val dataitems = List(DataItem(SpindleSpeed, 1223334444, 20.3333),

  • 0
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 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T16:49:17+00:00Added an answer on June 12, 2026 at 4:49 pm
    scala> val SpindleSpeed = "S"
    SpindleSpeed: java.lang.String = S
    
    scala> val Pressure = "P"
    Pressure: java.lang.String = P
    
    scala> val Load = "L"
    Load: java.lang.String = L
    
    scala> case class DataItem(name: String, timestamp: Long, value: Double)
    defined class DataItem
    
    scala> 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))
    dataitems: List[DataItem] = List(DataItem(S,1223334444,20.3333), DataItem(S,1223334450,21.3333), DataItem(S,1223334460,19.3333), DataItem(L,1223334444,70.0023), DataItem(L,1223334446,72.0023), DataItem(P,1223334444,20.3333))
    
    scala> dataitems.groupBy(_.timestamp).minBy(_._1)._2
    res2: List[DataItem] = List(DataItem(S,1223334444,20.3333), DataItem(L,1223334444,70.0023), DataItem(P,1223334444,20.3333))
    
    scala> 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

A message class: case class Message(username:String, content:String) A message list: val list = List(
Given: case class Person(name: String) and trying to do: scala> List(Person(Tom), Person(Bob)).sorted results in
I have three objects case class Metric(val name: String, val tags: Map[String, String]) case
Here is the pseudo case: class parent{ string name; //Some Property List<int> myValues; .......
Given: case class FirstCC { def name: String = ... // something that will
Given the following code: case class ChangeSet(field:String, from:Object, to:Object) private var changed:List[ChangeSet] = Nil
Given: case class Person(name:String = Bob, age:Int = 20) How can I accept the
Given: case class Foo(a: Int, b: String, c: Double) you can say: val params
Consider this class: case class Person(val firstName: String, val lastName: String, age: Int) val
I have a hierarchy like the following: case class A(val a: Long, val b:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.