Cldr.Unit.Math.add

You're seeing just the function add, go back to Cldr.Unit.Math module for more information.

Specs

add(Cldr.Unit.t(), Cldr.Unit.t()) ::
  Cldr.Unit.t() | {:error, {module(), String.t()}}

Adds two compatible %Unit{} types

Options

Returns

  • A %Unit{} of the same type as unit_1 with a value that is the sum of unit_1 and the potentially converted unit_2 or

  • {:error, {IncompatibleUnitError, message}}

Examples

iex> Cldr.Unit.Math.add Cldr.Unit.new!(:foot, 1), Cldr.Unit.new!(:foot, 1)
#Cldr.Unit<:foot, 2>

iex> Cldr.Unit.Math.add Cldr.Unit.new!(:foot, 1), Cldr.Unit.new!(:mile, 1)
#Cldr.Unit<:foot, 5281>

iex> Cldr.Unit.Math.add Cldr.Unit.new!(:foot, 1), Cldr.Unit.new!(:gallon, 1)
{:error, {Cldr.Unit.IncompatibleUnitsError,
  "Operations can only be performed between units with the same base unit. Received :foot and :gallon"}}