[swift-evolution] [Discussion] What is the future of tuples in Swift?

Anton Zhilin antonyzhilin at gmail.com
Thu Mar 2 18:07:58 CST 2017


2017-03-03 2:13 GMT+03:00 Slava Pestov <spestov at apple.com>:

Does newtype add any new capability that’s not already covered by defining
> a struct?
>
newtype would forward all members and conformances of the underlying type:

newtype RecordId = Int
let x: RecordId = 5let y = x + 10
extension RecordId {
    func load() -> String { … }
}
let a = x.load()let b = 42.load()  // error

newtypes aim to carry purely semantic information, in this case, that those
integers can be used to fetch records from a database. We get additional
members only when we are sure that semantic of current instance is
appropriate.

As a side effect, it essentially allows to declare one-liner structs with
pattern matching. But I agree with Jaden, just adding pattern matching to
structs feels more practical. And this feature is more or less orthogonal
to the core functionality of newtype.
​
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20170303/6f20677f/attachment.html>


More information about the swift-evolution mailing list