I have an array of tuples where the tuple contains some optional values:
let arrayOfTuples: [(Int, String?, String?)] = ...
How can I best remove from the array those tuples where the second element of the tuple is nil (no matter if the 3rd element is nil)?
When I use flatMap
like
let flatTuplesArray: [(Int, String, String)] = arrayOfTuples.flatMap({ ($0, $1, $2) })
then a tuple does not appear in the resulting flatTuplesArray
if the second or third element of the tuple is nil.
I want to apply flatMap
only on the first two elements of the tuple ($0 and $1) but the result array should still have tuples with three elements (and contain ""
for $2 nil values).