Created
May 2, 2025 12:40
-
-
Save rational-kunal/96ddaf8f0da2cd03f4edac190f2263ce to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| enum π¦<Value> { | |
| case πΊ(Value) | |
| case π΅ | |
| init(_ from: Value) { | |
| self = .πΊ(from) | |
| } | |
| } | |
| extension π¦: ExpressibleByNilLiteral { | |
| init(nilLiteral: ()) { | |
| self = .π΅ | |
| } | |
| } | |
| postfix operator β | |
| postfix func β<T>(value: T) -> π¦<T> { | |
| .πΊ(value) | |
| } | |
| postfix operator β | |
| postfix func β<T>(value: π¦<T>) -> T { | |
| switch value { | |
| case .πΊ(let v): | |
| return v | |
| case .π΅: | |
| fatalError("Cat is dead Bruh!") | |
| } | |
| } | |
| infix operator ββ‘οΈ: NilCoalescingPrecedence | |
| func ββ‘οΈ<T>(lhs: π¦<T>, rhs: @autoclosure () -> T) -> T { | |
| switch lhs { | |
| case .πΊ(let value): | |
| return value | |
| case .π΅: | |
| return rhs() | |
| } | |
| } | |
| @dynamicMemberLookup | |
| struct _π¦<Value> { | |
| private let storage: π¦<Value> | |
| init(from: π¦<Value>) { | |
| storage = from | |
| } | |
| subscript<T>(dynamicMember keyPath: KeyPath<Value, π¦<T>>) -> π¦<T> { | |
| switch storage { | |
| case .πΊ(let v): | |
| return v[keyPath: keyPath] | |
| case .π΅: | |
| return .π΅ | |
| } | |
| } | |
| } | |
| postfix operator β | |
| postfix func β<T>(value: π¦<T>) -> _π¦<T> { | |
| return _π¦(from: value) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment