[swift-evolution] Bool vs. Optional<Void>

Félix Cloutier felixcca at yahoo.ca
Thu Dec 17 09:44:33 CST 2015


I'm also against unification. I think that Krzysztof makes a good point showing what you can do on an Optional but shouldn't do on booleans.

In my opinion, going forward, code that uses Void? to signal failure should move to either Bool or to exceptions anyway. If this encourages the idiom to stay, it might not be in the best interest of the language.

Félix

> Le 17 déc. 2015 à 06:36:50, Krzysztof Siejkowski via swift-evolution <swift-evolution at swift.org> a écrit :
> 
>> Does it make sense to somehow unify them? Perhaps turn Bool into a typealias for Optional<Void> and move all of its conformances into (not yet supported) conditional conformances on Optional?
> 
> I’m against unifying those concepts, for two main reasons:
> 
> 1) These are two separate constructs. When Bool is turned into Optional<Void>, it’s logical to be able to map it to Optional<T>, to flatMap it, to forEach it etc. I can’t see a situation where mapping Bool to, let’s say, Optional<Array<String>> is a readable statement.
> 
> 2) Bool is a very basic type, one of the first to use when learning programming. Making it an alias for a widely more complicated construct will introduce special cases that will be misleading for those learning to code.
> 
> 
> 
> I believe the situation where Optional<Void> is used to indicate the existence or absence of particular condition could be better resolved. Two alternatives that come to mind:
> 
> a) „isDefined” method on Optional, converting any Optional to Bool
> 
> b) just writing optionalVoid.map { return true } ?? false at the end of your pipe to transform otherwise ambiguous Void? to Bool clearly expressing your thoughts.
> 
> 
> 
> Krzysztof
> 
> 
> 
>> 
>> 
>> -- 
>> Brent Royal-Gordon
>> Architechies
>> 
>> _______________________________________________
>> swift-evolution mailing list
>> swift-evolution at swift.org <mailto:swift-evolution at swift.org>
>> https://lists.swift.org/mailman/listinfo/swift-evolution <https://lists.swift.org/mailman/listinfo/swift-evolution>
>  _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org <mailto:swift-evolution at swift.org>
> https://lists.swift.org/mailman/listinfo/swift-evolution <https://lists.swift.org/mailman/listinfo/swift-evolution>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20151217/2b0cf880/attachment.html>


More information about the swift-evolution mailing list