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
unit_1
andunit_2
are compatible Units returned byCldr.Unit.new/2
Returns
A
%Unit{}
of the same type asunit_1
with a value that is the sum ofunit_1
and the potentially convertedunit_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"}}