We added a compact
method to Dictionary
when I was at Kickstarter and used it throughout:
- https://github.com/kickstarter/ios-oss/blob/996ba3d8990c85ac9b47dc15e6362a23af49ed69/KsApi/lib/Route.swift#L119-L123
- https://github.com/kickstarter/ios-oss/blob/996ba3d8990c85ac9b47dc15e6362a23af49ed69/KsApi/lib/Route.swift#L308-L312
- https://github.com/kickstarter/ios-oss/blob/a7636fa76c5c97bc87882ca17212be8e944c795e/Kickstarter-iOS/ViewModels/RootViewModel.swift#L108-L116
- https://github.com/kickstarter/ios-oss/blob/1b21ce9100edc2700b30f41432f4c6077febba69/Kickstarter-iOS/ViewModels/AppDelegateViewModel.swift#L942
I even recently added a filterMapValues
(and filteredValues
) to our code base at Point-Free:
We try to avoid mutation and write code that's declarative, so our uses tend to be where we want to pass a dictionary literal to a call site that expects non-optional values, but where some of our inputs may be optional.
These use cases may be minor enough to not require an implementation in the standard library, but we'll probably continue to add our own extension and benefit from it regardless. It's a bit messy to filter
and mapValues
everywhere (especially with the force unwrap). What we want is succinctness and safety.