T0041 — Functions: remaining existence
Part of the roadmap. Phase 1 · wave 6 · size S.
Goal
Complete N1 §5.1: empty, all, allTrue, anyTrue, allFalse, anyFalse, subsetOf, supersetOf, distinct, isDistinct.
Scope
Preserve the remaining contract from the original T0011 after exists/count moved into the small 0.2 scope. Reuse the existing collection/equality/predicate contracts and retain the implemented exists/count behaviour. Child T0044 supplies first for the original subset/superset and count suite cases; T0013 remains the full-completion prerequisite; this is a real completion-test requirement, not an addition to 0.2. This completion task is not assigned to 0.2 by the split and has no promised release version or due date.
Design
- All ten functions are in
functions/existence.ts, next toexistsandcount.allis a lambda function and shares the short-circuiting criteria loop ofexists(findItem()), so it keeps the canonical Boolean rule ofwhere, nested$this/$indexframes and the internal sync/async path. The other functions are value functions. Noarea:corefile changes. allstops at the first item whose criterion does not match, asexistsstops at a match (spec notes).allTrue,anyTrue,allFalseandanyFalseaccept only Booleans, including FHIRbooleannodes; any other item raiseseval/type-mismatch(spec notes).subsetOfandsupersetOfuseincludesEqual()fromsubsetting.ts, the membership rule ofintersectandexclude: only atrueequality makes an item a member, as 3.0.0 clarifies.distinctkeeps the last of equal items, in input order. Two items are equal only when=is true: false and empty both mean they are distinct, as 3.0.0 says, which is also the membership rule of|,intersectandexclude. So dates of different precision, quantities whose units cannot be related, an element that holds only extensions and complex values whose children cannot be compared all count as distinct, andisDistinctis never empty. The first implementation (#202) followed the test suite and returned empty; the owner chose 3.0.0 on 2026-11-10 (ADR-0001). R5testDistinct29andtestDistinct36, which expect empty, are spec exceptions (spec notes).
Acceptance criteria
- The spec examples for each remaining function are tests in
existence.test.ts. TheallTrue/anyTrue/allFalse/anyFalseexamples project withselect()(T0042); until it is merged they run with the test-onlytestSelect(). - Undetermined equality (for example dates with different precision) counts as distinct, as 3.0.0 says:
@2020.combine(@2020-01-01).isDistinct()istrue, anddistinct()keeps both dates. - Conformance groups
testAll,testSubSetOf,testSuperSetOfandtestDistinctpass, with complete originaltestExistsandtestCountcoverage retained, including R4/R5testCount3/testCount4once child T0044 supplies first. No missing-function case becomes a spec exception; the only exceptions in these groups are R5testDistinct29andtestDistinct36, which contradict 3.0.0. In R4 and R5, every test of these groups passes except four that also callselect()(T0042) and pass once it is merged:testAllTrue1,testAllTrue2,testDistinct3andtestDistinct6. - Existing public behaviour, errors and internal sync/async predicate compatibility are preserved; conformance baseline never regresses.