Skip to content

Instantly share code, notes, and snippets.

@therealbnut
Last active June 13, 2021 14:45
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save therealbnut/efea994e76080a8e3a397c23fda65b9e to your computer and use it in GitHub Desktop.
Save therealbnut/efea994e76080a8e3a397c23fda65b9e to your computer and use it in GitHub Desktop.
func keys_equal<T, U:Equatable>(_ keypath: Keypath<T,U>) -> (T,T) -> Bool {
return { $0[keypath: keypath] == $1[keypath: keypath] }
}
@available(OSX 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *)
extension Publisher {
    func removeDuplicates(matchingAll predicates: @escaping (Output, Output) -> Bool...)
        -> Publishers.RemoveDuplicates<Self>
    {
        return self.removeDuplicates { lhs, rhs in
            predicates.allSatisfy { $0(lhs, rhs) }
        }
    }
}
publisher.removeDuplicates(matchingAll: keys_equal(\.foo), keys_equal(\.bar))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment