Releases: ianmackenzie/elm-units
2.1.0
This release of elm-units
comes with just one user-visible change, the addition of a range
function for generating evenly-spaced values:
Quantity.range
{ start = Length.meters 2
, end = Length.meters 3
, steps = 5
}
--> [ Length.centimeters 200
--> , Length.centimeters 220
--> , Length.centimeters 240
--> , Length.centimeters 260
--> , Length.centimeters 280
--> , Length.centimeters 300
--> ]
Not visible is a ton of work that went into refactoring elm-units
internals to collect all conversion factors into one place. We now have a single nicely-readable Constants.elm
file with all the various conversion factors, for easy reuse and auditability. Thanks to @katjam for all her work on #23!
2.0.2
2.0.1
Add release notes link to README
2.0
elm-units
2.0 is out! This release adds several new quantity types, improves support for multiplication of different types of quantities, and adds a few more useful functions to the Quantity
module.
Updating code
To update code using elm-units
1.0 to 2.0, it should be sufficient to replace
Quantity.times
withQuantity.for
Quantity.product
with the newQuantity.times
Quantity.scaleBy
withQuantity.multiplyBy
For example:
----- 1.0 -----
length =
speed |> Quantity.times duration
area =
Quantity.product length width
halfLength =
Quantity.scaleBy 0.5 length
----- 2.0 -----
length =
speed |> Quantity.for duration
area =
length |> Quantity.times width
halfLength =
Quantity.multiplyBy 0.5 length
See Improved product support below for details.
New quantity types
This release adds support for several new quantity types:
Volume
(cubic meters) - thanks @katjam!Density
(kilograms per cubic meter) - thanks @katjam!AngularSpeed
(radians per second) - thanks @katjam!AngularAcceleration
(radians per second squared) - thanks @katjam!Capacitance
(farads) - thanks @ukarim!Inductance
(henries) - thanks @ukarim!SubstanceAmount
(moles) - thanks @ukarim!
Improved product support
Support for products of two quantities is now generalized and improved. Previously it was possible to square a quantity using Quantity.squared
or multiply two quantities with the same units using Quantity.product
(both of which gave you a result in Squared units
), but there was no way to multiply two quantities with different units. This is now supported - for example, it is now possible to multiply an Area
by a Length
to get a Volume
, or a Mass
by an Acceleration
to get a Force
. It is also now possible to divide these products, for example divide a Force
by a Mass
to get an Acceleration
.
This has led to a couple of breaking changes. First of all, the existing Quantity.times
(used when working with rates of change) has been renamed to Quantity.for
, and Quantity.times
is now used for multiplying quantities together, replacing the old Quantity.product
. For example:
area =
width |> Quantity.times length
volume =
area |> Quantity.times depth
force =
mass |> Quantity.times acceleration
In addition, for consistency with divideBy
, scaleBy
has been renamed to multiplyBy
. There are now three 'families' of multiplication/division functions for use in different contexts:
multiplyBy
anddivideBy
are used to multiply (scale) or divide aQuantity
by a plainInt
orFloat
times
,over
andover_
are used to work with quantities that are products of other quantities, likeArea
orVolume
per
,at
,at_
andfor
are used to work with rates of change, likeSpeed
or orCurrent
See Multiplication and division in the README for more details.
The new products support is made possible by a new Product units1 units2
units type. This has led to the redefinition of some existing units types:
Squared units
has been redefined asProduct units units
Cubed units
has been redefined asProduct (Product units units) units
Joules
has been redefined asProduct Newtons Meters
Newtons
has been changed fromRate Joules Meters
toProduct Kilograms MetersPerSecondSquared
New Quantity
functions
A few new functions have been added to the Quantity
module:
Quantity.lessThanOrEqualTo
andQuantity.greaterThanOrEqualTo
to go with the existingQuantity.lessThan
andQuantity.greaterThan
Quantity.interpolateFrom
to interpolate from one value to anotherQuantity.midpoint
to find the midpoint between two quantitiesQuantity.sortBy
to sort an arbitrary list of values by a derived quantity
1.0
elm-units
1.0 has been released! Check out the README for a fairly comprehensive introduction to the package, and don't be afraid to reach out if you have questions/comments/suggestions.
Big thanks to all those who helped with initial development of the package:
- @JoelQ and @adeschamps for in-depth and insightful discussions on Slack
- Everyone at the Elm NYC Meetup for providing comments on an early version of the package
- Everyone in the #api-design channel on the Elm Slack for their pre-release feedback
- @tiagorlampert and @mdevlamynck for making PRs to an Elm package that hadn't even been published yet!
(Sincere apologies to anyone I've missed.)