Unlike other modules in elm-units, this module contains two different
primary types:
Temperature, which is not actually a Quantity since temperatures don't
really act like normal quantities. For example, it doesn't make sense to
add two temperatures or find the ratio between them.Delta, which represents the difference between two temperatures. A Delta
is a Quantity since it does make sense to add two deltas to get a net
delta, find the ratio between two deltas (one rise in temperature might be
twice as much as another rise in temperature), etc.Since a Temperature value is not a Quantity, this module exposes specialized
functions for doing the operations on Temperature values that do make sense,
such as comparing two temperatures or sorting a list of temperatures. It's also
possible to find the delta from one temperature to another using minus,
and then add a Delta to a Temperature using plus.
A Delta represents the difference between two temperatures.
Tempereature deltas are stored as a number of Celsius degrees.
Construct a temperature from a number of degrees Celsius.
Convert a temperature to a number of degrees Celsius.
Construct a temperature from a number of degrees Fahrenheit.
Convert a temperature to a number of degrees Fahrenheit.
Construct a temperature from a number of kelvins.
Temperature.kelvins 300
--> Temperature.degreesCelsius 26.85Convert a temperature to a number of kelvins.
Temperature.degreesCelsius 0
|> Temperature.inKelvins
--> 273.15Absolute zero, equal to zero kelvins or -273.15 degrees Celsius.
Temperature.absoluteZero
--> Temperature.degreesCelsius -273.15Following the suggestion mentioned here,
this module uses (for example) celsiusDegrees to indicate a temperature delta
(change in temperature), in contrast to degreesCelsius which indicates an
actual temperature.
Construct a temperature delta from a number of Celsius degrees.
Convert a temperature delta to a number of Celsius degrees.
Construct a temperature delta from a number of Fahrenheit degrees.
Temperature.fahrenheitDegrees 36
--> Temperature.celsiusDegrees 20Convert a temperature delta to a number of Fahrenheit degrees.
Temperature.celsiusDegrees 10
|> Temperature.inFahrenheitDegrees
--> 18Shorthand for Temperature.celsiusDegrees 1 and Temperature.fahrenheitDegrees
1. Can be convenient to use with Quantity.per.
Check if one temperature is less than another. Note the argument order!
roomTemperature =
Temperature.degreesCelsius 21
Temperature.degreesFahrenheit 50
|> Temperature.lessThan roomTemperature
--> True
-- Same as:
Temperature.lessThan roomTemperature
(Temperature.degreesFahrenheit 50)
--> TrueCheck if one temperature is greater than another. Note the argument order!
roomTemperature =
Temperature.degreesCelsius 21
Temperature.degreesFahrenheit 50
|> Temperature.greaterThan roomTemperature
--> False
-- Same as:
Temperature.greaterThan roomTemperature
(Temperature.degreesFahrenheit 50)
--> FalseCheck if one temperature is less than or equal to another. Note the argument order!
Check if one temperature is greater than or equal to another. Note the argument order!
Compare two temperatures, returning an Order
value indicating whether the first is less than, equal to or greater than the
second.
Temperature.compare
(Temperature.degreesCelsius 25)
(Temperature.degreesFahrenheit 75)
--> GT
Temperature.compare
(Temperature.degreesCelsius 25)
(Temperature.degreesFahrenheit 77)
--> EQ(Note that due to floating-point roundoff, you generally shouldn't rely on temperatures comparing as exactly equal.)
Check if two temperatures are equal within a given delta tolerance. The tolerance must be greater than or equal to zero - if it is negative, then the result will always be false.
Temperature.equalWithin (Temperature.fahrenheitDegrees 1)
(Temperature.degreesCelsius 25)
(Temperature.degreesFahrenheit 75)
--> False
Temperature.equalWithin (Temperature.fahrenheitDegrees 3)
(Temperature.degreesCelsius 25)
(Temperature.degreesFahrenheit 75)
--> TrueFind the minimum of two temperatures.
Temperature.min
(Temperature.degreesCelsius 25)
(Temperature.degreesFahrenheit 75)
--> Temperature.degreesFahrenheit 75Find the maximum of two temperatures.
Temperature.max
(Temperature.degreesCelsius 25)
(Temperature.degreesFahrenheit 75)
--> Temperature.degreesCelsius 25Add a Delta to a Temperature to get a new Temperature.
Temperature.degreesCelsius 25
|> Temperature.plus
(Temperature.celsiusDegrees 7)
--> Temperature.degreesCelsius 32If you want to subtract a Delta from a Temperature, you can negate
the delta first and then call plus.
Subtract one Temperature from another to get a Delta. Note the argument
order!
-- 25 degrees Celsius is 77 degrees Fahrenheit
start =
Temperature.degreesCelsius 25
end =
Temperature.degreesFahrenheit 80
end |> Temperature.minus start
--> Temperature.fahrenheitDegrees 3
start |> Temperature.minus end
--> Temperature.fahrenheitDegrees -3Given a lower and upper bound, clamp a given temperature to within those bounds. Say you wanted to clamp a temperature to be between 18 and 22 degrees Celsius:
lowerBound =
Temperature.degreesCelsius 18
upperBound =
Temperature.degreesCelsius 22
Temperature.degreesCelsius 25
|> Temperature.clamp lowerBound upperBound
--> Temperature.degreesCelsius 22
Temperature.degreesFahrenheit 67 -- approx 19.4 °C
|> Temperature.clamp lowerBound upperBound
--> Temperature.degreesFahrenheit 67
Temperature.absoluteZero
|> Temperature.clamp lowerBound upperBound
--> Temperature.degreesCelsius 18Find the minimum of a list of temperatures. Returns Nothing if the list
is empty.
Temperature.minimum
[ Temperature.degreesCelsius 20
, Temperature.kelvins 300
, Temperature.degreesFahrenheit 74
]
--> Just (Temperature.degreesCelsius 20)Find the maximum of a list of temperatures. Returns Nothing if the list
is empty.
Temperature.maximum
[ Temperature.degreesCelsius 20
, Temperature.kelvins 300
, Temperature.degreesFahrenheit 74
]
--> Just (Temperature.kelvins 300)Sort a list of temperatures from lowest to highest.
Temperature.sort
[ Temperature.degreesCelsius 20
, Temperature.kelvins 300
, Temperature.degreesFahrenheit 74
]
--> [ Temperature.degreesCelsius 20
--> , Temperature.degreesFahrenheit 74
--> , Temperature.kelvins 300
--> ]Sort an arbitrary list of values by a derived Temperature. If you had
rooms =
[ ( "Lobby", Temperature.degreesCelsius 21 )
, ( "Locker room", Temperature.degreesCelsius 17 )
, ( "Rink", Temperature.degreesCelsius -4 )
, ( "Sauna", Temperature.degreesCelsius 82 )
]then you could sort by temperature with
Temperature.sortBy Tuple.second rooms
--> [ ( "Rink", Temperature.degreesCelsius -4 )
--> , ( "Locker room", Temperature.degreesCelsius 17 )
--> , ( "Lobby", Temperature.degreesCelsius 21 )
--> , ( "Sauna", Temperature.degreesCelsius 82 )
--> ]
A temperature such as 25 degrees Celsius or 80 degrees Fahrenheit.