[[Swift]] provides an special syntax to write closures, that can be more and more succinct if certain conditions are met. An example of an anonymous function can be seen in this snippet of code, that performs a reverse sort on a list:
```swift
let reversed = original.sorted(by: { (first: String, second: String) -> Bool in
return first > second
})
```
First part of this syntax that can be skipped is the type signature of the function, since it is already constrained to the outermost caller (in this case, `.sorted`):
```swift
let reversed = original.sorted(by: { first, second in
return first > second
})
```
When the function only receives one function, we can use [[Trailing Closure Syntax|trailing closure syntax]], like:
```swift
let reversed = original.sorted { first, second in
return first > second
}
```
The last shorthand we can use is refer to the arguments as positional placeholders, as:
```swift
let reversed = original.sorted {
return $0 > $1
}
// Or, in a single line:
let reversed = original.sorted { $0 > $1 }
```
This is however not super readable, and (probably) should not be used if:
- There are more than two parameters (`$2`, `$3`, etc);
- Each argument is being used more than once (you probably can benefit from using a name then);
- The code is too long.
Some relevant functions to take into account (and that can use these kinds of shorthands) are `array.filter()`, `array.map()` and the aforementioned `array.sorted()`