Update `Binding` Helpers

- Rename `Binding.map` to `Binding.compactMap`
- Add `Binding.map` with an updated signature

These should now match the naming conventions of similar
methods on types.
This commit is contained in:
Daniel Haight 2021-11-21 14:28:08 +00:00
parent 883ce52011
commit 24c21d4965
1 changed files with 8 additions and 1 deletions

View File

@ -74,7 +74,14 @@ extension Binding {
)
}
func map<T>(extract: @escaping (Value) -> T, embed: @escaping (T) -> Value?) -> Binding<T> {
func map<T>(extract: @escaping (Value) -> T, embed: @escaping (T) -> Value) -> Binding<T> {
Binding<T>(
get: { extract(wrappedValue) },
set: { wrappedValue = embed($0) }
)
}
func compactMap<T>(extract: @escaping (Value) -> T, embed: @escaping (T) -> Value?) -> Binding<T> {
Binding<T>(
get: { extract(wrappedValue) },
set: {