I can destructure a tuple of tuple easily:
let tt = (2, (3, 4))
let (a, (b, c)) = tt
b // => 3
I'd like to do the same when declaring a closure, for example I thought I could write:
[tt].map { (a, (b, c)) in
// Use b
}
XCode complains with "Unnamed parameters must be written with the empty name".
Only way I got it to "work" was:
[tt].map { (a, tuple: (b: Int, c: Int)) in
// Use tuple.b
}
This has two drawbacks I'd like to avoid:
- I need to use
tuple.b
instead ofb
- I need to specify the types of
b
andc
BTW, my use case is that I want to do a reduce
with index so I'm trying using array.enumerate().reduce