[swift-evolution] where clauses on enum cases

Rex Fenley rex at remind101.com
Tue Mar 14 14:44:43 CDT 2017

I've run into a problem recently when using generics with enums where I'm
required to specify the type for a generic that isn't used for the enum
case that's constructed.


protocol Mapping {
    associatedtype Destination

enum EvictionPolicy {
    case append
    case replace

enum Map<T: Mapping, U: Mapping> where U.Destination: Collection {
    case object(T)
    case collection(U, EvictionPolicy)

class IntMapping: Mapping {
    typealias Destination = Int

class IntsMapping: Mapping {
    typealias Destination = [Int]

// Must specify types for generics that are not in use
let o = Map<IntMapping, IntsMapping>.object(IntMapping())
let c = Map<IntMapping, IntsMapping>.collection(IntsMapping(),

What I'd like to be able to do is the following

enum Map<T: Mapping> {
    case object(T)
    case collection(T, EvictionPolicy) where T.Destination: Collection

Could this be added to the language?


Rex Fenley  |  IOS DEVELOPER

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

More information about the swift-evolution mailing list