Arguments Have a Shorthand, Too
As it turns out, you don’t even have to declare s1 and s2 as the parameters. You can use a special syntax to get the nth parameter. You can write $0 to get the first parameter and $1 to get the second parameter and so on. Now the closure gets even shorter because you no longer need to declare the names of parameters. You can pass the closure to sort like so:
sort(&names,{$0 < $1})
You are able to write this because of all the things mentioned before plus the fact that you don’t have to declare parameters if you use a special argument shorthand. Why declare something that does not need to be declared? You don’t need the return keyword, and you don’t need to declare a type for the parameters because it is inferred. ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access