언제봐도 어렵고 헷갈리는 이 두가지 개념....

scala> def modN(n: Int, x: Int) = ((x % n) == 0)

modN: (n: Int, x: Int)Boolean

scala> modN(5, _ : Int)

res0: Int => Boolean = <function1>

scala> res0(10)

res2: Boolean = true

scala> def modNCurried(n: Int)(x: Int) = ((x % n) == 0)

modNCurried: (n: Int)(x: Int)Boolean

scala> modNCurried(5)

<console>:13: error: missing argument list for method modNCurried

Unapplied methods are only converted to functions when a function type is expected.

You can make this conversion explicit by writing `modNCurried _` or `modNCurried(_)(_)` instead of `modNCurried`.


scala> modNCurried(5)(15)

res6: Boolean = true

scala> modNCurried(5)_

res7: Int => Boolean = <function1>

scala> res7(15)

res8: Boolean = true

Posted by 용식

댓글을 달아 주세요