jankapunkt/js-set-extension

Containment

jankapunkt opened this issue · 6 comments

There needs to be a boolean operation on instances of Sets that allow the following:

What you say: "if A is a proper superset of B, ..."
What you type: if (A.isProperSuperset(B)) {
note: After some nail biting, I settled on the word 'of' being builtin to functions. We say "f of x" and we write "f(x)". We don't write the of, but instead it is as-if the open-parenthesis is the of.

What you say: "if A is a proper subset of B, ..."
What you type: if (A.isProperSubset(B)) {

branch: matt/containment

jankapunkt said:

Looks fine. I assumed that there is no reason to implement this on the Set class level (i.e. for arbitrary args) as I saw no use-case for that. Can you confirm this?

This PR would be part of the 2.x.x release.

matt (i) said:

The only use case I could think of is if people want to verify that a list of sets is a chain of subsets.

If < denotes "subset", then a person wanting to check if

A < B < C < D

could do something like

Set.isSubset(A, B, C, D)

. I don't know how often somebody would want to do this, but it is convenient. It's up to you.

If it is not a big deal to add (introducing more complexity than already exists) and you think it could be a use case then let's add it. With this package completeness and validity is more interesting than performance.

This is typically called "a chain of subsets". As a random example, see (http://www.mathcounterexamples.net/uncountable-chain-of-subsets-of-the-natural-numbers/)

I don't know if we would want to call it isChainOfSubsets to be unambiguous.

What do you think?

I'm really on the fence. We might leave this for after version 2 release.

Can this be closed as it is now already merged into 2.x.x?

Yeah. We can leave isChainOfSubsets stuff for another time.