This is in an auxiliary file for a Swift playground.
extension LimitedPrimalityViaTrialDivisionNodesSequence.Iterator.Node {
/// Creates a clone of the given node, along with clones of its followers.
convenience init(cloning source: LimitedPrimalityViaTrialDivisionNodesSequence.Iterator.Node) {
self.init(source.value)
next = source.next.map { Self(cloning: $0) }
}
}
I originally had "Node
" as the parameter type and in the closure in the last line of code. The compiler didn't accept them. I changed them to "Self
," but it only accepted its use within the initializer. I had to use the fully qualified form in the initializer's argument. Why? I should be able to use the class's name as a parameter type. (I tried "Iterator.Node
," but that didn't work either.)
If it needs to be picky over derived classes, we could use Self
to always mean the exact class and the class's name for that class or any derived types.
In my code, Node
is a final class
, if that makes a difference.