4 ms·
> Your whole life was a lie. > Optionals were a 2-case enum the entire time. I'm not sure what I was supposed to think instead of this. But my question is, a
by mrkeen 2y ago
> Your whole life was a lie.
> Optionals were a 2-case enum the entire time.
I'm not sure what I was supposed to think instead of this.
But my question is, as a Swift programmer are you allowed to write this code yourself?
> The ?, !, and ?? you know and love?
Can you write an Either<> or a Parser<> (2- and 1-case enums respectively) which is driven by the known-and-loved ?, !, and ?? - or did the language designers keep that for themselves?
- Someone 2y ago> Can you write an Either<> or a Parser<> (2- and 1-case enums respectively) which is driven by the known-and-loved ?, !, and ?? - or did the language designers keep that for themselves? https://docs.swift.org/swift-book/documentation/the-swift-programming-language/lexicalstructure#Operators https://docs.swift.org/swift-book/documentation/the-swift-pr...: “Although you can define custom operators that contain a question mark (?), they can’t consist of a single question mark character only. Additionally, although operators can contain an exclamation point (!), postfix operators can’t begin with either a question mark or an exclamation point. Note The tokens =, ->, //, /, /, ., the prefix operators <, &, and ?, the infix operator ?, and the postfix operators >, !, and ? are reserved. These tokens can’t be overloaded, nor can they be used as custom operators.” So, you can’t use the same operator names. I would think you can implement them using different names, though.