I created my own type of sequence, and I want the function to accept any sequence as a parameter. (I want to use both sets and my sequence types on it)
Something like that:
private func _addToCurrentTileset(tilesToAdd tiles: SequenceType)
Is there any way I can do this?
It seems relatively simple, but I just can't figure it out. The Swift toolchain tells me: Protocol 'SequenceType' can only be used as a generic constraint because it has Self or associated type requirements , and I donβt know how to create a protocol that matches SequenceType and the Self requirement from it.
I can exclude a related requirement like c, but not Self:
protocol EnumerableTileSequence: SequenceType { associatedtype GeneratorType = geoBingAnCore.Generator associatedtype SubSequence: SequenceType = EnumerableTileSequence }
Now, if I say that I can eliminate the requirement itself, then with such a protocol definition, other objects of type collectionType, such as arrays, sets will not match it.
Link: my user sequences are all subclasses of an enum type defined as:
public class Enumerator<T> { public func nextObject() -> T? { RequiresConcreteImplementation() } } extension Enumerator { public var allObjects: [T] { return Array(self) } } extension Enumerator: SequenceType { public func generate() -> Generator<T> { return Generator(enumerator: self) } } public struct Generator<T>: GeneratorType { let enumerator: Enumerator<T> public mutating func next() -> T? { return enumerator.nextObject() } }
source share