I'm confused about the first line of code.
And what's the difference between the first line and the second line?
val cond: (Int, Int) => Boolean = (...) //confused
val cond = (x: Int, y: Int) => x > y //anonymous function
It can be a bit daunting at first, but all Scala declarations are the same shape:
val <name>[: <type>] = <value>
If the type is not there the compiler will set it to the type of the value
So the first case breaks down like this:
name is condtype is (Int, Int) => Booleanvalue is (...)The second case breaks down like this:
name is condvalue is (x: Int, y: Int) => x > ytype is inferred to be (Int, Int) => BooleanIn both cases cond is a function that takes two Ints and returns a Boolean.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With