Hi Swift users,
I just ran into a bug after a Swift 4 migration where we expected [String]
and got [Character] from a flatMap since flatMap will flatten the String
since it's now a collection. While I understand why flatMap behaves this
way now that string are collections, in testing this I found some weird
behaviour...
var strArr = ["Hi", "hello"]
let result = strArr.flatMap { x in
return x
}
The type of results ends up being [Character] in the above case. However,
adding a print statement changes things.
var strArr = ["Hi", "hello"]
let result = strArr.flatMap { x in
print(x)
return x
}
In this case, result is of type [String]
This seems like a bug, or is this expected Swift behaviour?
Thanks,
Santiago
_______________________________________________
swift-users mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-users