Avatar
@swift-5.1.5 protocol AnyEquatableBase { associatedtype Value var value: Value { get } func isEqual(to other: Self) -> Bool } extension AnyEquatableBase { func isEqual(to other: Self) -> Bool { false } } extension AnyEquatableBase where Value: Equatable { func isEqual(to other: Self) -> Bool { value == other.value } } struct AnyEquatable<T>: AnyEquatableBase { var value: T } print(AnyEquatable(value: "abc").isEqual(to: AnyEquatable(value: "abc"))) print(AnyEquatable(value: ()).isEqual(to: AnyEquatable(value: ()))) print(AnyEquatable(value: String.self).isEqual(to: AnyEquatable(value: String.self))) print(AnyEquatable(value: { }).isEqual(to: AnyEquatable(value: { })))