Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

320
Views
kotlin; agrupar por varios campos

¿Cómo puedo hacer un groupBy en mi código por tres o más campos? Mi código es como a continuación:

 val nozzleSaleReport = nozzleStateList.groupBy { {it.shift.id},{it.createUser.id},{it.nozzle.id} // Here I need to add these three fields for grouping operation }.map { entry -> val max: Float = (entry.value.maxBy { it.nozzleState.finalLitreMechanical }?.nozzleState!!.finalLitreMechanical ?: 0).toString().toFloat() val min: Float = (entry.value.minBy { it.nozzleState.finalLitreMechanical }?.nozzleState!!.finalLitreMechanical ?: 0).toString().toFloat() NozzleSaleReport(entry.value[0].createUser.name, entry.value[0].shift.name, (max - min).toInt(),entry.value[0].shift.id, entry.value[0].nozzle.id, entry.value[0].nozzle.name) }.let { println(it) }
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Digamos que la clase de los elementos de tu colección es NozzleState .

Desea agrupar los estados de las boquillas por ID de turno, crear una ID de usuario y una ID de boquilla.

Si lo entiendo correctamente, desea un grupo diferente para cada combinación distinta de ID de turno, crear ID de usuario e ID de boquilla.

Por lo tanto, debe crear una clase que represente dicha combinación (pongamos un nombre si es Key ) y agrupe los elementos por su Key :

 data class Key(val shiftId: String, val createUserId: String, val nozzleId: String) fun NozzleState.toKey() = Key(shift.id, createUser.id, nozzle.id) nozzleStateList.groupBy { it.toKey() }
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!