Skip to content

Instantly share code, notes, and snippets.

@cjnevin
Last active November 2, 2022 09:00
Show Gist options
  • Save cjnevin/ffc89e6aad413c7d5f2224c7d2fb07e0 to your computer and use it in GitHub Desktop.
Save cjnevin/ffc89e6aad413c7d5f2224c7d2fb07e0 to your computer and use it in GitHub Desktop.
@dynamicMemberLookup
struct Assert<T> {
let value: T
subscript<Value>(dynamicMember keyPath: KeyPath<T, Value>) -> Assert<Value> {
.init(value: value[keyPath: keyPath])
}
}
func assert<T>(_ root: T, _ closure: (Assert<T>) throws -> Void) rethrows {
try closure(assert(root))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment