canjs / can-query-logic

Perform data queries and compare queries against each other. Provides logic useful for data caching and real-time behavior.

Home Page:https://canjs.com/doc/can-query-logic.html

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Expand set-logic capabilities to use additional laws to simplify defineComparison requirements

justinbmeyer opened this issue · comments

Currently, one needs to define a union, intersection, difference and reverse difference between two set types. One should also define the difference between the universal set and the set type:

defineComparison(TypeA, TypeB,{union, intersection, difference})
defineComparison(TypeB, TypeA, {difference})
defineComparison(set.UNIVERSAL, TypeA, {difference})

There's some set algebra laws that could simplify these requirements:

  • B \ A = Aᶜ ∩ B - If UNIVERSAL \ TypeA is defined and the type of that result TypeC has an intersection with TypeB, then TypeB \ TypeA doesn't need to be defined.
  • A ∩ B = A \ (A \ B) - Intersection doesn't need to be defined if the difference between TypeA and the result of (TypeA \ TypeB) is defined.