15 ms·
Your example produces very distinguishable results. e.g. if Array.first finds a nil value it returns Optional<Type?>.some(.none), and if it doesn't find any val
by ecedeno 9mo ago
Your example produces very distinguishable results. e.g. if Array.first finds a nil value it returns Optional<Type?>.some(.none), and if it doesn't find any value it returns Optional<Type?>.none
The two are not equal, and only the second one evaluates to true when compared to a naked nil.
- _flux 9mo agoWhat language is this? I'd expect a language with a ? -type would not use an Optional type at all. In languages such as OCaml, Haskell and Rust this of course works as you say.
- _rend 9mo agoThis is Swift, where Type? is syntax sugar for Optional<Type>. Swift's Optional is a standard sum type, with a lot of syntax sugar and compiler niceties to make common cases easier and nicer to work with.
- _flux 9mo agoRight, so it's not like a union type Type | Null. Then naturally it works the same way as in the languages I listed.