1

val の型ではなく、関数評価の結果に基づいてパターン マッチングを行う方法を探しています。例えば、

def f1(x:String):Boolean = if (x contains ("Helllo")) true else false
val caller="Hello"

caller match 
{
  case f1(caller) => println ("caller said hello")
  case _ => println ("caller did not say hello")
}

何か案が ?

4

2 に答える 2

2

パターンガードを使用したい:

caller match 
{
  case x if f1(x) => println ("caller said hello")
  case _ => println ("caller did not say hello")
}
于 2013-09-07T16:30:55.843 に答える