When I define a curried function like:
def fx(x: Int) (f: Int => Int): Int = f(x)
I can call it using:
fx(2)(x => x * x)
But cannot call it using:
(fx 2) (x => x * x)
However
If we take the foldLeft fun from scala std library, with signature:
def foldLeft[B](z: B)(f: (B, A) => B): B
I can call it using:
(xs foldLeft 0 ) ( _ + _)
But cannot call it using:
xs foldLeft (0) ( _ + _)
Question:
Why in case if my defined fun, I can call it using f(x)(fx)
, but cannot call it using (f x)(fx)
, However in case of foldleft
, I can call it using (obj f x)(fx)
but cannot call it using obj f (x) (fx)
?
Hint: I know this is because operator precedence, but need detailed answer