Skip to content

Releases: ianmackenzie/elm-units

2.1.0

18 Jul 01:39
Compare
Choose a tag to compare

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

19 Jan 20:05
Compare
Choose a tag to compare

Fix to API docs link in README (thanks @katjam!)

2.0.1

15 Jan 03:42
Compare
Choose a tag to compare

Add release notes link to README

2.0

15 Jan 03:32
Compare
Choose a tag to compare
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 with Quantity.for
  • Quantity.product with the new Quantity.times
  • Quantity.scaleBy with Quantity.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 and divideBy are used to multiply (scale) or divide a Quantity by a plain Int or Float
  • times, over and over_ are used to work with quantities that are products of other quantities, like Area or Volume
  • per, at, at_ and for are used to work with rates of change, like Speed or or Current

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 as Product units units
  • Cubed units has been redefined as Product (Product units units) units
  • Joules has been redefined as Product Newtons Meters
  • Newtons has been changed from Rate Joules Meters to Product Kilograms MetersPerSecondSquared

New Quantity functions

A few new functions have been added to the Quantity module:

  • Quantity.lessThanOrEqualTo and Quantity.greaterThanOrEqualTo to go with the existing Quantity.lessThan and Quantity.greaterThan
  • Quantity.interpolateFrom to interpolate from one value to another
  • Quantity.midpoint to find the midpoint between two quantities
  • Quantity.sortBy to sort an arbitrary list of values by a derived quantity

1.0

05 Oct 04:22
Compare
Choose a tag to compare
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.)