Unit Fun v0.5.4 UnitFun.UnitTypes
Provides functions for applying units on top of bare values. Normally imported
import UnitFun.UnitTypes
ten_pence = 10 |> with_units(Pence)
# or
twenty_pence = 20 <~ Pence
Summary
Functions
<~ is provided as a shorthand for calling with_units
Takes a bare value and wraps it in a struct with units
Functions
<~ is provided as a shorthand for calling with_units
Example usage
iex> import UnitFun.UnitTypes
iex> 5 <~ UnitFun.Examples.SimpleUnit
%UnitFun.Value{units: %UnitFun.Examples.SimpleUnit{size: 1, type: :primitive_unit}, value: 5}
Takes a bare value and wraps it in a struct with units.
Examples
With a module defined as units
iex> 5 |> UnitFun.UnitTypes.with_units(UnitFun.Examples.SimpleUnit)
%UnitFun.Value{units: %UnitFun.Examples.SimpleUnit{size: 1, type: :primitive_unit}, value: 5}
Errors thrown for undefined units
iex> 5 |> UnitFun.UnitTypes.with_units(:anyoldatom)
** (UnitFun.Errors.MissingUnitsError) Units anyoldatom are not defined