Skip to content

Instantly share code, notes, and snippets.

@vasily-kirichenko
Last active February 27, 2018 12:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vasily-kirichenko/1c036d448413ec93a6c2a4ff191a0e2d to your computer and use it in GitHub Desktop.
Save vasily-kirichenko/1c036d448413ec93a6c2a4ff191a0e2d to your computer and use it in GitHub Desktop.
case class Person(name: String, flag: Boolean)
def sortedKeyList(xs: List[List[Person]]) = {
xs.flatten
.map(_.name)
.distinct
.sortBy(identity)
.mkString(", ") match {
case "" => "<none>"
case s => s
}
}
class Tests extends FunSuite with Matchers {
test("sorted key list") {
def people(xs: List[String]) = xs.map(Person(_, flag = true))
val data = List(
(Nil, Nil, "<none>"),
(List("fred"), List("barney", "wilma"), "barney, fred, wilma"),
(List("fred"), Nil, "fred"),
(List("fred"), List("fred", "barney"), "barney, fred"))
for ((a, b, res) <- data)
sortedKeyList(List(people(a), people(b))) should equal(res)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment