Skip to content

Instantly share code, notes, and snippets.

@matthewcheok
Created February 10, 2020 15:20
Show Gist options
  • Save matthewcheok/c8891c5ba5459aa08a62f75955e7f5d6 to your computer and use it in GitHub Desktop.
Save matthewcheok/c8891c5ba5459aa08a62f75955e7f5d6 to your computer and use it in GitHub Desktop.
import CasePaths
public protocol CaseProviding {}
extension CaseProviding {
public subscript<Value>(casePath casePath: CasePath<Self, Value>) -> Value? {
get { casePath.extract(from: self) }
set {
guard let value = newValue else { return }
self = casePath.embed(value)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment