Select the earlier-or-equal time from two shift starts.

← Operators and Expressions · Ref: Q1218

The <=? coalescing operator returns the lesser-or-equal of two values, handling unset gracefully.

  earlierOrEqual() as pure
    -> left as Time, right as Time
    <- rtn as Time: left <=? right

If both times are set and different, <=? returns the earlier one (same as <?). If both are equal, it returns that value. If one is unset, it returns the set one. If both unset, the result is unset.

The difference from <? appears when values are equal: <=? and <? both return the same result, but <=? semantically includes the equality case. The full coalescing family is <?, >?, <=?, >=?. See Q1227 for all four operators side by side.

Do not confuse any coalescing operator with :=? (guarded assignment). See Q1226 for the contrast.

Example

defines module qa.operators.coalescelte.time

  defines function

    earlierOrEqual() as pure
      ->
        left as Time
        right as Time
      <- rtn as Time: left <=? right

  defines program

    CoalesceLteTimeDemo()
      stdout <- Stdout()

      // === BOTH SHIFTS SCHEDULED — returns the earlier ===

      morningShift <- 06:00
      dayShift <- 09:00
      firstStart <- earlierOrEqual(morningShift, dayShift)
      stdout.println(`First shift starts: ${firstStart}`)

      // === EQUAL TIMES — returns the shared time ===

      shiftA <- 08:00
      shiftB <- 08:00
      sameStart <- earlierOrEqual(shiftA, shiftB)
      stdout.println(`Both start at: ${sameStart}`)

      // === ONE SHIFT UNSCHEDULED — returns the scheduled one ===

      scheduledShift <- 07:30
      unscheduledShift <- Time()
      onlyShift <- earlierOrEqual(scheduledShift, unscheduledShift)
      stdout.println(`Scheduled shift: ${onlyShift}`)

      // === BOTH UNSCHEDULED — result is unset ===

      missingShift <- Time()
      noShiftB <- Time()
      bothMissing <- earlierOrEqual(missingShift, noShiftB)
      if bothMissing?
        stdout.println(`Shift: ${bothMissing}`)
      else
        stdout.println("No shifts scheduled")

Common mistakes

E50030 — '<=' is a comparison that yields Boolean, so assigning 'left <= right' to a Time return is a type mismatch; use the coalescing '<=?' which returns the lesser-or-equal Time and handles unset values. See ek9 -h E50030 for details.

Incorrect:

<- rtn as Time: left <= right

Correct:

<- rtn as Time: left <=? right
Other ways to ask this
  • How do I find the lesser-or-equal of two Time values when one shift might be unscheduled?
  • Two shifts have start times but one could be empty — pick the earlier or equal time.
  • In Java I'd need null checks before comparing with isBefore or equals. What does EK9 use?
  • Migrating from Python where I use min() for times — does EK9 have a less-than-or-equal coalescing?

Coming from another language?

Java: a == null ? b : b == null ? a : !a.isAfter(b) ? a : b. Python: min(a, b) handles equality naturally. Kotlin: listOfNotNull(a, b).minOrNull(). EK9: left <=? right — one operator handles all cases including equality.

Keywords: schedule, coalescing, equal, shift, earlier, <=?, less-or-equal, time