메시지 클래스 :사용자 이름으로 메시지를 그룹화하는 방법은 무엇입니까?
case class Message(username:String, content:String)
메시지 목록 :
val list = List(
Message("aaa", "111"),
Message("aaa","222"),
Message("bbb","333"),
Message("aaa", "444"),
Message("aaa", "555"))
어떻게 그룹 이름으로 메시지를에 다음과 같은 결과를 얻을 :
List("aaa"-> List(Message("aaa","111"), Message("aaa","222")),
"bbb" -> List(Message("bbb","333")),
"aaa" -> List(Message("aaa","444"), Message("aaa", "555")))
사용자 경우, 의미 여러 명의 메시지를 게시 한 다음 다른 사용자가 게시 할 때까지 그룹화하십시오. 명령서는 보관해야합니다.
는
API를 검토해 보셨습니까? 'List'를보고'groupBy'라는 메시지가 있습니다 ... – ziggystar
@ziggystar,'groupBy'는 사용자 "aaa"의 모든 메시지를 함께 그룹화하기 때문에 여기에서 사용할 수 없습니다. 이것은 내가 원하는 것이 아닙니다. – Freewind
죄송합니다, 마지막 문장을 읽지 않았습니다. – ziggystar