pointfreeco / swift-case-paths

🧰 Case paths extends the key path hierarchy to enum cases.
https://www.pointfree.co/collections/enums-and-structs/case-paths
MIT License
921 stars 108 forks source link

Support matching on partial key paths using `is` #134

Closed lukeredpath closed 10 months ago

lukeredpath commented 10 months ago

Updated the signature to be a PartialCaseKeyPath which is all that is required for this function to work.

Makes it possible to write algorithms that operate on a collection of case key paths for a given type, for example:

extension CasePathable {
  func isOneOf<CaseKeyPaths: Sequence>(_ keyPaths: CaseKeyPaths) -> Bool where CaseKeyPaths.Element == PartialCaseKeyPath<Self> {
    keyPaths.contains(where: { self.is($0) })
  }
}