[swift-evolution] Either protocol syntax

Adrian Zubarev adrian.zubarev at devandartist.com
Thu Feb 2 15:29:30 CST 2017


Look for Disjunctions (logical ORs) in type constraints. ;)

It’s rejected.



-- 
Adrian Zubarev
Sent with Airmail

Am 2. Februar 2017 um 22:26:44, Rex Fenley via swift-evolution (swift-evolution at swift.org) schrieb:

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  
|  BLOG  
 |  FOLLOW
US  
 |  
 LIKE US
_______________________________________________
swift-evolution mailing list
swift-evolution at swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20170202/d964f486/attachment.html>


More information about the swift-evolution mailing list