Closed athibodeau-hibernum closed 5 years ago
This seems like it could get a bit complicated for more complex Range definitions, so I'm not that keen to implement it unless there's a strong desire for it. Do you have a use-case where this would be useful?
In the package management application that we are developing, if a dependency is resolved to a version that is higher than the minimum allowed, we want to bump the minimum of the dependency to that point:
var minRange = new Range(">=" + resolvedVersion.ToString());
var newRange = currentRange.Intersect(minRange);
Without an access to the parsed components, we will have to parse it by ourselves, reinventing Range.
Otherwise, what about making the internals of Range available? With proper interfaces and separation, Range could remain immutable, while easing the creation of new ranges based on current ranges.
Ok that seems like a pretty legitimate use case and it would be good to be able to make that possible. Exposing the internal Comparator and ComparatorSet classes would be more flexible and powerful but might take a little bit more thinking about how to do that nicely, so I'd lean towards going with just providing an Intersect method.
Thanks for implementing Intersect!
Since the internal constituents of a parsed range are not exposed, it would be great to have methods to manipulate ranges. I would suggest Union, Intersect and Except. This would allow, for example: