Challenge: Flattening nested optionals

Well, some people seem to think it’s a good idea to work with constructs like a dictionary of AnyKeyPaths to optional properties. I don’t personally vouch for that design, but it apparently exists.

Mostly I just wanted to see if I could, and it wasn’t immediately obvious how to test whether an Any is actually an Optional for recursive unwrapping.

What is more difficult, is to programmatically identify the bottom-most Wrapped type in an arbitrary stack of Optionals that includes Any?, especially if some layer other than the innermost is actually .none.