(Int -> Int) means a closure (or function) that takes an Int parameter as a parameter and returns an Int .
The syntax for declaring a closure type is:
(parameters) -> (return_types)
parameters is a list of parameters that the closure accepts as input, and return_types is a list of values ββreturned by the closure. Both are tuples, but in the case of a single parameter or one type of return, the bracket identifying the tuple can be omitted. So, for example, clousure, expecting one parameter and returning one value, can be defined as:
parameter -> return_type
In your case:
Int -> Int
is a closure that has 1 input parameter of type Int and returns a Int
The return type is enclosed in parentheses so that it is clear what the return type is, but you can also write it as:
func makeIncrementer() -> Int -> Int {
This, in my opinion, is less readable than
func makeIncrementer() -> (Int -> Int) {
source share