Created
January 22, 2015 11:26
-
-
Save seraphr/4a312681b37afa1d4f64 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
scala> case class Base(id: String, data: String) | |
defined class Base | |
scala> case class Merged(id: String, dataList: Seq[String]) | |
defined class Merged | |
scala> | |
scala> val tSeq = Seq(Base("c", "c2"), Base("a", "a1"), Base("c", "c3"), Base("a", "a2"), Base("b", "b"), Base("c", "c1")) | |
tSeq: Seq[Base] = List(Base(c,c2), Base(a,a1), Base(c,c3), Base(a,a2), Base(b,b), Base(c,c1)) | |
scala> tSeq.groupBy(_.id).map { | |
| case (id, bases) => Merged(id, bases.map(_.data)) | |
| } | |
res0: scala.collection.immutable.Iterable[Merged] = List(Merged(b,List(b)), Merged(a,List(a1, a2)), Merged(c,List(c2, c3, c1))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment