Agarunov
(Anton Agarunov)
1
I have a question about how properly store operator in a variable.
let function1: (Int, Int) -> Int = (+) // ok. Single element tuple?
let function2: (Int, Int) -> Int = + // error: Expected expression after unary operator
// But
[1,2,3].reduce(0, (+)) // ok
[1,2,3].reduce(0, +) // ok
Is this a bug or an expected behaviour?
Seems like this is the same workaround as the one for putting operators in an array:
let operators: [(Int, Int) -> Int] = [(+), (-)] // Ok
let operators: [(Int, Int) -> Int] = [+, -] // Error
This bug is tracked by [SR-5509] Array of operators parsing issue · Issue #48081 · apple/swift · GitHub
1 Like
Agarunov
(Anton Agarunov)
3
huh, so this is known issue.
Thanks!