// *** before: ***
// either the exact type was spelled out, and the implementation leaked
// into the signature and into every caller
func makeOld() -> LazyMapSequence<Range<Int>, Int> {
return (0..<3).lazy.map { $0 * 2 }
}
// or a protocol was returned, and then Self requirements were forbidden:
// a function could not return Equatable or Collection at all
// *** in version 5.1: ***
func make() -> some Collection {
return (0..<3).lazy.map { $0 * 2 }
}
protocol Shape { func area() -> Double }
struct Circle: Shape { func area() -> Double { 3.14 } }
func shape() -> some Shape { Circle() }
// the caller knows only "some Shape", the compiler knows the exact type:
// no box, no dynamic dispatch, and Self requirements are allowed.
// The whole of SwiftUI stands on this: var body: some View