LoginSignup
0
0

More than 5 years have passed since last update.

Scalaのmatchにて変数の束縛

Last updated at Posted at 2013-07-20

matchのcase内で"@"を使うことで変数を束縛できる。
変数名 @ パターン のような感じ

以下のような感じ

def service(request: String) = {
    val splitRequest:Array[String] = request.split(" ");
    splitRequest match {
        case Array(cmdString, other @ _*) =>
             println(other)
        case _ =>
   }
}

sevice("hoge fuga piyo")とか呼び出すと'Vector(fuga,piyo)'という出力になる

fuga以降のArrayデータを束縛できた

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0