Your ifSome is essentially a re-implementation of ??, phrased as a method on self instead of a binary free function.
Your example similarly shows a different way to use ??, one that avoids the specific bug in hand:
// edit: the fortold doom is not happening in this example ;)
for i in (maybeHugeRange ?? 0..<0).reversed() { // doom occurs here
print(i) // your app will jetsam without ever reaching here
break
}
only you're expressing it with your method instead of the nil-coalescing operator. But it amounts to the same thing.
I appreciate that and I confirmed as much in the thread (just after the two method examples I posted).
Surely the real issue at hand is the deviation that has been created as a result of the optional ? chaining syntactic affordance that precedes the optional unwrap ?? something which is not so easy to reproduce with the method alternative.
A number of inconsistencies have been highlighted in respect of the syntactic approach to this. I'd certainly be far more positive about this overall if we could somehow deal that. I'm certainly in no way pushing to remove either ? or ??
Picking up from @Ling_Wang's above question the ifSome method defaults to Range<Int> and in turn to ReverseCollection<Range<Int>>, where as ? optional chaining in your code failure example defaults to ReverseCollection<[Int]> -- implying optional chaining picks the wrong reverse method.