How to write the function isFunction in scala?

后端 未结 3 1686
长发绾君心
长发绾君心 2021-01-29 02:48

How can i write a isFunction function in scala, so that this works:

def isFunction(x:Any) = /* SomeCode */

println(isFunction(isFunction _)) //true
println(isFu         


        
3条回答
  •  清歌不尽
    2021-01-29 03:20

    Quite ugly, but it works:

    def isFunction(x:Any) = x match {
      case _: Function0[_] => true
      case _: Function1[_, _] => true
      case _: Function2[_, _, _] => true
      ...
      case _: Function22[...] => true
      case _: PartialFunction[_, _] => true
      case _ => false
    }
    

提交回复
热议问题