I'm trying to use operator >
as default function argument:
Playground execution failed: error: StackSorting.playground:27:63:
error: expected expression after unary operator
func sort<T>(..., compare: (T, T) -> Bool = >) where T: Comparable { }
^
I solved it, but... Does somebody know a shorter way?
func sort<T>(..., compare: (T, T) -> Bool = { $0 > $1 }) where T: Comparable { }
You can use the operator as default value for the parameter, you only have to enclose it in parentheses:
func sort<T>(..., compare: (T, T) -> Bool = (>)) where T: Comparable { }
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