Today I would like to ask what does the => SomeType
mean. I found it used in this article. It's in the part 'The Sequential Combinator'.
Thanks for any answer!
Show activity on this post. => is the "function arrow". It is used both in function type signatures as well as anonymous function terms. () => Unit is a shorthand for Function0[Unit] , which is the type of functions which take no arguments and return nothing useful (like void in other languages).
It means when you call the method, the argument is not evaluated before the method is executed, but rather, it is evaluated each time it is referred to inside the method.
_1 is: _ = wildcard parameter _1 = first parameter in method parameter list But when used together with .
It means a block of code that you can run.
So for example:
scala> def doTwice(op: =>Unit) = {op; op}
doTwice: (op: => Unit)Unit
scala> doTwice({println("Hi")})
Hi
Hi
In this case the =>Unit
is {println("Hi")}
Here "SomeType" is Unit because println
doesn't produce a value. If it produced an Int
, it would be =>Int
.
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