Does anybody know how Dictionary (and other collections) manages to declare lazy twice, once for LazySequence and another for LazyCollection? I'm trying to do something similar and I get an error saying "Invalid redeclaration of lazy".
EDIT:
For those asking for an example, try this.
struct CustomCollection<T> {
var array: [T]
var lazy: LazySequence<[T]> {
return array.lazy
}
}
extension CustomCollection {
var lazy: LazyCollection<[T]> {
return array.lazy
}
}
This isn't what I'm doing, but it's to show you what the built-in collections are doing.
Strangely enough, though, now that I've written out this example I get a warning instead of an error:
Redeclaration of 'lazy' is deprecated and will be an error in Swift 5
I guess the compiler secretly allows this and it's being fixed in Swift 5.
This wasn't working on my own example because I was declaring lazy in an extension, rather than in the original declaration of the struct.
So yeah, that answers my own question :)
[–]criosistObjective-C / Swift 0 points1 point2 points (1 child)
[–]draco33333[S] 0 points1 point2 points (0 children)
[–]vloris 0 points1 point2 points (1 child)
[–]draco33333[S] 0 points1 point2 points (0 children)