[swift-evolution] Proposal for generic protocols

Tal Atlas me at tal.by
Thu Dec 3 16:12:06 CST 2015


With the awesome expansion of protocol oriented programming that swift has
allowed, the lack of generic protocols has felt noticeably lacking and
painful in some cases. I made an in depth proposal here:
https://github.com/tal/swift-evolution/blob/tal/generic-protocol-proposal/proposals/NNNN-add-generic-protocols.md

But the tl;dr is this:

protocol Validator<TypeToValidate> {
  var value: TypeToValidate { get set }
  var valueIfValid: TypeToValidate? { get }
}

struct FooStringValidator: Validator<String> {
  //... implementation
}

let stringValidator: Validator<String>

Look forward to hearing some feedback.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20151203/5a83e7f3/attachment.html>


More information about the swift-evolution mailing list