Skip to content

Instantly share code, notes, and snippets.

@oshiro-kazuma
Last active August 29, 2015 14:10
Show Gist options
  • Save oshiro-kazuma/1f2b3ed9e0c9af4edd96 to your computer and use it in GitHub Desktop.
Save oshiro-kazuma/1f2b3ed9e0c9af4edd96 to your computer and use it in GitHub Desktop.
scalaで末尾再帰処理
// 自分の中でこれはイディオムとしてfixした
def rec(x: String, xs: Seq[String]): String = {
xs match {
case Seq() => x
case Seq(y, ys@_*) =>
rec(s"$x:$y", ys)
}
}
//scala> rec("start", List("1","2","3"))
//res1: String = start:1:2:3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment