[swift-users] How to rewrite this snippet without `existentials`?

Adrian Zubarev adrian.zubarev at devandartist.com
Fri Dec 2 11:05:39 CST 2016

For anyone interested. The correct idea should go into this direction one day:

public class Router<B> {
    open protocol Connection<T> : class {
        var router: Router<T> { get set }
        func performWith(_ value: T)
    var _connections: [Connection<B>] = []
    public typealias Connections = Any<Collection> where Collection.Index == Int, Collection.Iterator.Element == B
    // Immutable view without `append` etc.
    public connections: Connections { return self._connections }
    public func register(_ connection: Connection<B>) { … }  
    public func performWith(_ value: B) {
        self._connections.forEach { $0.performWith(value) }
The main idea is to link different nodes (class instances) and call a function on the other end with a specific type parameter. Enums with associated types would come really handy here.

Adrian Zubarev
Sent with Airmail

Am 2. Dezember 2016 um 17:35:25, Tino Heth (2th at gmx.de) schrieb:

Thanks, that works party as needed but I just realize this main idea here is exactly an example where one would need generic protocols
That's right — and I guess they rank quite hight on the general evolution-wishlist ;-)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20161202/a33ab2b1/attachment.html>

More information about the swift-users mailing list