2 ms·
I'm going to disagree: new_set = old_set.union( another_set, element_comparator_func); If you allow some helper functions or an interface to do things suc
by Roboprog 13y ago
I'm going to disagree:
new_set = old_set.union( another_set, element_comparator_func);
If you allow some helper functions or an interface to do things such as compare/hash members, it's totally doable. Extra points for passing the helper(s) into the constructor.
Yes, you can still mismatch set types, but the casting/type-assertion in the helpers will fail with an explicit reason.
- Roboprog 13y agoAlmost forgot: in Go, classes aren't "closed". While you cannot "monkey patch" and change existing methods, you can define new functions, such as my_set_comparator, that accept each given type as "this". You would then make a new interface, such as my_set_element, which defines method my_set_comparator, and any data types for which you had defined my_set_comparator would automagically meet the new interface.