[swift-evolution] Either protocol syntax

Rex Fenley rex at remind101.com
Thu Feb 2 15:26:35 CST 2017


Hello, I believe there was some discussion about this quite awhile ago. I
was wondering if there's any interest in including a protocol 'or' type
that would be the intersection of two protocols. This could be really
useful in situations where a framework that the user has no control over
implements a portion of some often used protocol. Such as specialized
collections from an Database framework that don't implement
RangeReplaceableCollection but have a set of methods that are equivalent.
The user can then implement a protocol that is the intersection of those
set of methods and not duplicate code.

Simplified example:

protocol Animal {
    var hasEars: Bool { get }
    func grow()
}

protocol Plant {
    var isGreen: Bool { get }
    func grow()
}

protocol LivingThing = Plant | Animal // or a different syntax

LivingThing's is as follows
{
    func grow()
}

-- 

Rex Fenley  |  IOS DEVELOPER

Remind.com <https://www.remind.com/> |  BLOG <http://blog.remind.com/>
 |  FOLLOW
US <https://twitter.com/remindhq>  |  LIKE US
<https://www.facebook.com/remindhq>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20170202/44f0f8dd/attachment.html>


More information about the swift-evolution mailing list