Default-initable Protocol

Probably the most generic abstraction that is useful alongside init() might be append(contentsOf:). As a single protocol:

protocol Appendable {
  init() {}
  mutating func append(contentsOf other: Self)
}
Those familiar with the concept may prefer the name monoid: https://en.wikipedia.org/wiki/Monoid

Swift's collection APIs could inherit from this protocol (or combination of DefaultConstructible & Appendable). This would allow for a bit more generality when writing code that can create/combine things that aren't collections.

1 Like