Fix: Use Go Generics to Consolidate Subset functions#5444
Fix: Use Go Generics to Consolidate Subset functions#5444FirePheonix wants to merge 1 commit intohyperledger:mainfrom
Conversation
Signed-off-by: Shubham Singh <[email protected]>
b5f52f5 to
36631fa
Compare
|
It seems you've hit some unit tests. |
|
hey @pfi79 , it's the the tests are running for so long and then failing, it might even be a race condition. |
When your pipe turns green locally, I'm ready to consider it further. So far, I've restarted your pr pipe 7-8 times and so far everything is bad. |
|
hey @pfi79 , i ran the tests on my PR replica, on shubhammms#3. I was earlier re running all jobs by commiting on it, that didn't work. Been trying to figure it out for a whole day.. |
|
YES. |

Description
subsetOfGroups,subsetOfPolicies, andsubsetOfValueswere three identical functions differing only in map value type.A TODO had already existed since the code was written acknowledging the duplication, but noted the signatures "need to be different".
At the time, Go had no generics, so there was no clean way to unify them without losing type safety.
Go 1.18 introduced generics. This PR resolves the TODO by replacing all three functions with a single subsetOf[V any] function, letting the compiler infer the concrete type at each call site. ZERO behavior change - the logic is identical.
Now, 60 lines -> 10 lines of code
I have also added a new test case for partial error corresponding to the changes I've done.