[swift-evolution] Reconsidering the (Element -> T?) variant of SequenceType.flatMap

Kevin Ballard kevin at sb.org
Fri Dec 4 17:52:30 CST 2015

Can implicit optional promotion not be redefined to only occur when the
destination type is explicitly optional (as opposed to being generic)?
The problem you describe sounds like it could affect third-party code as
well if anyone has a reason to declare a protocol and extend Optional to
conform to it.

-Kevin Ballard

On Fri, Dec 4, 2015, at 03:37 PM, Dmitri Gribenko wrote:
> On Fri, Dec 4, 2015 at 3:34 PM, Kevin Ballard <kevin at sb.org> wrote:
> > Personally, I'd be in favor of making Optional conform to SequenceType. I've filed a radar on it before, and I seem to recall a message (probably to this list) yesterday suggesting the exact same thing.
> This would be an interesting direction, but we have discussed it a
> long time ago, and found an issue in the way it would interact with
> implicit promotions to optionals.  Basically, in a call to a function
> accepting a Sequence, one would be able to write any non-sequence,
> non-optional value, that would be implicitly promoted to optional, and
> thus eligible to be passed as a Sequence.  This is the only argument
> for not adding this conformance that I know of, but it is a show
> stopper unfortunately.
> Dmitri
> -- 
> main(i,j){for(i=2;;i++){for(j=2;j<i;j++){if(!(i%j)){j=0;break;}}if
> (j){printf("%d\n",i);}}} /*Dmitri Gribenko <gribozavr at gmail.com>*/

More information about the swift-evolution mailing list