Checking Required Membership with Subsets
A subset test verifies that every required element appears in an available set.
- Source
- Anbloq
- Language
- English
- Created
- Updated
- Chapters
- 4
- Reading time
- 1 min
In this article4 chapters
Find the missing part
A booking requiring rooms A and B can be satisfied by availability A, B, and C. Availability A and C leaves B missing. The required set minus the available set identifies that witness. Set difference explains the direction of the query.
Specify what duplicates mean
If two requests for room A in the same interval require two distinct resources, turning inputs into sets loses that multiplicity. Use counts for requests and availability when each key has a finite supply.[1]
Return the missing subset when diagnosis matters
A field validator requires {id, title}. For provided fields {title, date}, the subset check fails and subtracting provided fields from required fields gives {id}. This directly explains the error. Extra fields need a separate decision. A validator rejecting every extra field enforces equality of key sets, whereas an extensible input may accept date. Test a record containing all mandatory fields and one extra. See set difference.
Pair key coverage with checks on values
A record containing an empty title satisfies a pure key subset check. Whether it meets the schema depends on the value rule for title. Check keys before retrieving them to avoid treating absence as an empty value. The empty requirement set is a subset of every set, which is useful when a feature has no mandatory extensions. Test missing and present-but-empty separately. See records with optional fields.