Select the longer warranty period from two product options.
← Operators and Expressions · Ref: Q1216
The >? coalescing maximum operator returns the longer of two Duration values, handling unset gracefully.
longerWarranty() as pure -> left as Duration, right as Duration <- rtn as Duration: left >? right
If both durations are set, >? returns the longer one. If one is unset (no warranty info), it returns the available warranty. If both are unset, the result is unset.
This is a COMPARISON operator — it picks the larger value. Do not confuse it with :=? (guarded assignment), which assigns only if the target is unset. See Q1226 for a side-by-side contrast.
See Q1092 for min/max coalescing overview. See Q1210 for <? minimum on Duration.
Example
defines module qa.operators.coalescemax.duration defines function longerWarranty() as pure -> left as Duration right as Duration <- rtn as Duration: left >? right defines program CoalesceMaxDurationDemo() stdout <- Stdout() // === BOTH WARRANTIES KNOWN — returns the longer === standardWarranty <- P1Y extendedWarranty <- P3Y bestWarranty <- longerWarranty(standardWarranty, extendedWarranty) stdout.println(`Best warranty: ${bestWarranty}`) // === ONE WARRANTY UNKNOWN — returns the available one === knownWarranty <- P2Y unknownWarranty <- Duration() onlyWarranty <- longerWarranty(knownWarranty, unknownWarranty) stdout.println(`Available warranty: ${onlyWarranty}`) // === BOTH UNKNOWN — result is unset === missingA <- Duration() missingB <- Duration() noWarranty <- longerWarranty(missingA, missingB) if noWarranty? stdout.println(`Warranty: ${noWarranty}`) else stdout.println("No warranty information available")
Other ways to ask this
- How do I find the maximum of two Duration values when one product has no warranty info?
- Two product variants have different warranty periods but one might be unspecified — pick the longer.
- In Java I'd need null checks before comparing Duration objects. What does EK9 use?
- Migrating from C# where I use TimeSpan comparison with nullable checks — what is the EK9 pattern?
Coming from another language?
Java: a == null ? b : b == null ? a : a.compareTo(b) >= 0 ? a : b. Python: max(d for d in [a, b] if d is not None). Go: custom function with nil checks on time.Duration. EK9: left >? right — one operator handles all cases.
Keywords: coalescing, duration, period, >?, maximum, product, warranty, longer