Hello community,
does Swift compiler translates the code from case A in efficient way into machine code?
case A
array
.compactMap { $0 as? UIView }
.forEach {
// do some operation
}
or for performance reasons better to write the code in the next way?
case B
array
.compactMap {
guard let value = $0 as? UIView else { return nil }
// do some operation
}
Examples are very trivial and with clear input, and of course we always can look at a case, and apply the way which depends on the context, and prefer readability over pre-optimization, where we don't expect millions of values, which in that case we would use imperative approach for a processing.
Could you tell in details about Swift compiler, does it handle such cases or maybe it in plans to cover such cases in a future?