Skip to content

Instantly share code, notes, and snippets.

@jasdev
Created July 20, 2020 01:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jasdev/ca7b06625bfcff697d6e9f77cc774d0a to your computer and use it in GitHub Desktop.
Save jasdev/ca7b06625bfcff697d6e9f77cc774d0a to your computer and use it in GitHub Desktop.
Implemented Binding.map.
extension Binding {
func map<Subject>(
get: @escaping (Value) -> Subject,
set: @escaping (inout Value, Subject) -> Void
) -> Binding<Subject> {
.init(
get: { get(self.wrappedValue) },
set: { set(&self.wrappedValue, $0) }
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment