Skip to content

Instantly share code, notes, and snippets.

@linqing
Created February 26, 2012 14:57
Show Gist options
  • Save linqing/1917183 to your computer and use it in GitHub Desktop.
Save linqing/1917183 to your computer and use it in GitHub Desktop.
if else for
case class Message(username: String, content: String)
val list = List(Message("aaa", "111"), Message("aaa", "222"),
Message("bbb", "333"), Message("aaa", "444"))
if (list.isEmpty) Nil
else
list.head :: (
for (List(m1, m2) <- list.sliding(2))
yield if (m1.username == m2.username)
m2.copy(username = "") else m2).toList
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment