Proposal: Add areCasesEqual Functionality to allow for comparing cases while ignoring their associated values #219
Closed
vladyslavsosiuk
started this conversation in
Ideas
Replies: 1 comment 3 replies
-
@vladyslavsosiuk The library currently ships with this functionality: ExampleEnum.allCasePaths[case1] == ExampleEnum.allCasePaths[case2] Does this satisfy your needs? Anything we could do to improve documentation and discoverability? |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Summary
I would like to propose adding a utility function,
areCasesEqual
, to the library to simplify and enhance the comparison of enum cases. This functionality leveragesCasePathable
andCasePathReflectable
to determine if two enum cases are equal, regardless of their associated values. This can be particularly useful in scenarios where enums with associated values need to be compared by their case type alone.Problem Statement
Currently, comparing enum cases with associated values requires custom logic or boilerplate code to ignore the associated values and focus solely on the case type. This can lead to repetitive code and potential errors when maintaining large enums. Also such custom logic doesn't always guarantee exhaustive implementation.
For example:
Proposed Solution
Introduce a static function,
areCasesEqua
, as an extension toCasePathable
. This function will compare two enum cases by their case type, ignoring associated values.Here is the interface:
Example Usage
Request for Feedback
If this proposal is accepted, I would be happy to work on a PR implementing this functionality.
Beta Was this translation helpful? Give feedback.
All reactions