Select the lower temperature from two weather stations.

← Operators and Expressions · Ref: Q1213

The <? coalescing minimum operator returns the lesser of two Float values, handling unset gracefully.

  lowerTemp() as pure
    -> left as Float, right as Float
    <- rtn as Float: left <? right

If both temperatures are set, <? returns the lower one. If one is unset (station offline), it returns the active station's reading. If both are unset, the result is unset.

This is a COMPARISON operator — it picks the smaller 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 Q1227 for all four coalescing operators.

Example

defines module qa.operators.coalescemin.float

  defines function

    lowerTemp() as pure
      ->
        left as Float
        right as Float
      <- rtn as Float: left <? right

  defines program

    CoalesceMinFloatDemo()
      stdout <- Stdout()

      // === BOTH STATIONS REPORTING — returns the lower temperature ===

      stationAlpha <- 18.5
      stationBravo <- 22.3
      coldest <- lowerTemp(stationAlpha, stationBravo)
      stdout.println(`Coldest reading: ${coldest}`)

      // === ONE STATION OFFLINE — returns the active one ===

      activeStation <- 15.7
      offlineStation <- Float()
      onlyReading <- lowerTemp(activeStation, offlineStation)
      stdout.println(`Active station: ${onlyReading}`)

      // === BOTH STATIONS OFFLINE — result is unset ===

      downAlpha <- Float()
      downBravo <- Float()
      noReading <- lowerTemp(downAlpha, downBravo)
      if noReading?
        stdout.println(`Temperature: ${noReading}`)
      else
        stdout.println("No weather data available")

Common mistakes

E50001 — EK9 has no Math.min() — use the coalescing-minimum operator '<?', which returns the lesser value and handles unset operands. See ek9 -h E50001 for details.

Incorrect:

<- rtn as Float: Math.min(left, right)

Correct:

<- rtn as Float: left <? right
Other ways to ask this
  • How do I find the minimum of two Float values when one station might be offline?
  • Two weather stations report temperature but one might be down — pick the lower reading.
  • In Java I'd need null checks before Math.min for nullable doubles. What does EK9 use?
  • Migrating from Python where I use min() with None filtering for floats — what is the EK9 pattern?

Coming from another language?

Java: a == null ? b : b == null ? a : Math.min(a, b). Python: min(t for t in [a, b] if t is not None). Go: custom function with nil checks. EK9: left <? right — one operator handles all cases.

Keywords: station, weather, temperature, coalescing, <?, lower, minimum, float