mirror of
https://github.com/ichmagmaus111/ghostgram.git
synced 2026-11-02 22:04:28 +01:00
Ghostgram for iOS, rebuilt from scratch on Telegram iOS 13.0. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
37 lines
1.2 KiB
Swift
37 lines
1.2 KiB
Swift
import Foundation
|
|
|
|
private struct NoNeighborInfluence: Equatable {
|
|
}
|
|
|
|
/// A type-erased `Equatable` value.
|
|
///
|
|
/// Unlike `AnyHashable` this imposes no `Hashable` requirement on payloads — nothing hashes a
|
|
/// neighbor descriptor, and `Equatable` is the weaker constraint.
|
|
public struct AnyEquatable: Equatable {
|
|
private let value: Any
|
|
private let isEqualTo: (Any) -> Bool
|
|
|
|
public init<T: Equatable>(_ value: T) {
|
|
self.value = value
|
|
self.isEqualTo = { other in
|
|
guard let other = other as? T else {
|
|
return false
|
|
}
|
|
return other == value
|
|
}
|
|
}
|
|
|
|
public static func == (lhs: AnyEquatable, rhs: AnyEquatable) -> Bool {
|
|
return lhs.isEqualTo(rhs.value)
|
|
}
|
|
|
|
/// Recovers the payload as `T`. `T` may be a concrete type or a protocol (facet).
|
|
public func base<T>(_ type: T.Type) -> T? {
|
|
return self.value as? T
|
|
}
|
|
|
|
/// Payload for items whose neighbors read nothing about them. A single shared constant, so it
|
|
/// compares equal to itself and never causes a neighbor relayout.
|
|
public static let noNeighborInfluence = AnyEquatable(NoNeighborInfluence())
|
|
}
|