question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

pull 'Set'-producing operations | & ~ up to 'Collection'

See original GitHub issue

I was longing for Set operators/operations in Range instances. Namely union, intersection but why not also complement and exclusiveUnion.

Sure, I can do set(3..5).union(set(4..6)), but is there any reason that Range couldn’t satisfy Set? I read through #3557 and the current interfaces and their implementations and although I didn’t perhaps catch everything, I felt I should ask.

Since all operations except intersection may result in split ranges, the implied return value of Set is actually just fine. One could of course have a more specific Range<Element> intersectionWithRange(Range<Element> other) for convenience.

For these set operations one would naturally not care if the ranges are increasing or decreasing - the result would be the same i.e. the result would be normalized.

As for an actual implementation it would perhaps be beneficial to override the default implementations from the Set interface for more efficient operation (as long as the “other” set is of same type as “this” set), but they would still be “just Sets”…

Thanks for listening…

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:32 (26 by maintainers)

github_iconTop GitHub Comments

4reactions
gavinkingcommented, Nov 16, 2018

I’ve implemented this idea (it was really straightforward) and it seems to be working well. I’ll push it to a branch later.

2reactions
gavinkingcommented, Nov 16, 2018

One possible reasonable thing to do would be to define | and & for the Collection interface, but have them always produce Sets. That is, simply pull the current union() and intersection() methods up to Collection from Set.

That would be a change with pretty minimal impact on the language, that makes the existing | and & operators much more useful.

For example, [1->"hello", 3->"world"] | map { 1->"goodbye", 2->"sweet" } would be equal to set { 1->"hello", 3->"world", 1->"goodbye", 2->"sweet" }.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error while creating new container instance #13378 - GitHub
When I try to create a new container instance, using Azure SDK, I receive one of three results (I cannot see any pattern,...
Read more >
Chapter 1. Reactive Programming with RxJava - O'Reilly
A single Observable stream is always serialized, but each Observable stream can operate independently of one another, and thus concurrently and/or in parallel....
Read more >
Extraction of color features in the spectral domain to recognize ...
In this paper, we are proposing a novel automated method to recognize centroblast (CB) cells from non-centroblast (Non-CB) cells for computer-assisted ...
Read more >
US20090266484A1 - Method for the Serial Application of Labels on ...
In a conventional mode of operation, initially a set of label rows is completed with the tape driving mechanism at rest in that...
Read more >
RANK | CDP Public Cloud - Cloudera Documentation
... places in the result set, producing the same result for duplicate values, and skipping values in the sequence to account for the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found