Challenge: Finding base type of nested optionals

So you want to flatten T?...? into T?, is that correct?

Thanks! This'll work. I've never naturally encountered a type with more than three levels of optionality. I just thought it would be nice to have a function that could handle any number of levels.

Yes, exactly. I couldn't have said it more succinctly myself. Although I think that @Jens solution is all that I'll ever need. There's no need to go beyond about 5 levels of optionality. I'm just someone who is extremely idealistic.

But, again, in a reasonable (let alone ideal) situation/program/design, you'd never need anything like this! :slight_smile:

To me, not caring about the number of levels in Optional<Optional<…>> is the same as not caring about the number of levels in eg Array<Array<…>>, it just doesn't make sense, it's an indication of a deeper problem.

Yes, yes, I know.

1 Like