Find the earlier of two delivery dates, even if one is unknown.
← Operators and Expressions · Ref: Q1208
The <? coalescing minimum operator returns the lesser of two values, handling unset gracefully. Wrap it in a pure function.
earlierOf() as pure -> left as Date, right as Date <- rtn as Date: left <? right
If both dates are set, <? returns the earlier one. If one is unset, it returns the set one. If both are unset, the result is unset. This is a COMPARISON operator — it does NOT assign anything.
Do not confuse <? with :=? (guarded assignment). The :=? operator assigns a value only if the target variable is unset — it is not a comparison. See Q1226 for a side-by-side contrast.
See Q1092 for min/max coalescing overview.
Example
defines module qa.operators.coalescemin.dates defines function earlierOf() as pure -> left as Date right as Date <- rtn as Date: left <? right defines program CoalesceMinDatesDemo() stdout <- Stdout() // === BOTH DATES SET — returns the earlier === deliveryA <- 2024-11-15 deliveryB <- 2024-11-08 earliest <- earlierOf(deliveryA, deliveryB) stdout.println(`Earliest delivery: ${earliest}`) // === ONE DATE UNSET — returns the set one === confirmedDate <- 2024-12-01 pendingDate <- Date() available <- earlierOf(confirmedDate, pendingDate) stdout.println(`Available date: ${available}`) // === BOTH DATES UNSET — result is unset === unknownA <- Date() unknownB <- Date() noDate <- earlierOf(unknownA, unknownB) if noDate? stdout.println(`Date: ${noDate}`) else stdout.println("No delivery date available") // === INLINE USAGE === shippingDate <- 2024-10-20 warehouseDate <- 2024-10-25 pickupDate <- shippingDate <? warehouseDate stdout.println(`Pickup by: ${pickupDate}`)
Common mistakes
E50001 — EK9 has no Math.min(); use the '<?' coalescing minimum operator, which also handles unset values. See ek9 -h E50001 for details.
Incorrect:
Math.min(left, right)
Correct:
left <? right
Other ways to ask this
- How do I pick the minimum of two optional dates using <? coalescing?
- A supplier sends two possible delivery dates but one might be missing — pick the earlier one.
- In Java I'd need null checks and compareTo to find the earlier date. What does EK9 offer?
- Migrating from Python where I use min(d1, d2) with None checks — what is the EK9 equivalent?
Coming from another language?
Java: d1 == null ? d2 : d2 == null ? d1 : d1.isBefore(d2) ? d1 : d2. Python: min(d for d in [d1, d2] if d is not None). Rust: [d1, d2].iter().flatten().min(). EK9: left <? right — one operator handles all cases.
Keywords: <?, delivery, coalescing, comparison, unset, date, minimum, earlier