I know that optional chaining like this:
someOptional?.someProperty
is basically
someOptional.map { $0.someProperty }
However, I found that doing both at the same time is not possible:
// someOptional?.someProperty evaluates to an optional type, right?
// so the map method should exist!
someOptional?.someProperty.map(someClosure) // can't find "map"
Here's an MCVE:
let s: String? = "Hello"
s?.hashValue.map(Double.init)
I think writing something like the above is more readable than:
s.map { Double($0.hashValue) }
So I would really like a way to use optional chaining and map
at the same time.
How do I do this?