Last active
June 13, 2021 14:45
-
-
Save therealbnut/efea994e76080a8e3a397c23fda65b9e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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