Avatar
@swift-5.2.5 protocol Container { associatedtype Item var item: Item { get } } struct MyContainer<T>: Container { var item: T } extension Container { func transform<T>(_ f: (Self.Item) -> T) -> some Container { MyContainer(item: f(self.item)) } } let c1 = MyContainer(item: 1) let c2 = c1.transform { item in item + 1 } let item: Int = c2.item print(item)