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

Krzysztof Siejkowski krzysztof at siejkowski.net
Thu Dec 17 05:36:50 CST 2015


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
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/3aca7b8e/attachment.html>


More information about the swift-evolution mailing list