Cldr.Unit.Format (Cldr Units v3.5.0-rc.0) View Source

Link to this section Summary

Functions

Traverses the components of a unit and resolves a list of base units with their gramatical case and plural selector definitions for a given locale.

Traverses a unit's decomposition and invokes a function on each node of the composition tree.

Link to this section Functions

Link to this function

grammar(unit, options \\ [])

View Source (since 3.5.0)

Specs

grammar(Cldr.Unit.t(), Keyword.t()) ::
  grammar_list() | {grammar_list(), grammar_list()}

Traverses the components of a unit and resolves a list of base units with their gramatical case and plural selector definitions for a given locale.

This function relies upon the internal representation of units and grammatical features and is primarily for the support of formatting a function through Cldr.Unit.to_string/2.

Arguments

  • unit is a t:Cldr.Unit or a binary unit string

Options

Returns

Examples

Traverses a unit's decomposition and invokes a function on each node of the composition tree.

Arguments

  • unit is any unit returned by Cldr.Unit.new/2

  • fun is any single-arity function. It will be invoked for each node of the composition tree. The argument is a tuple of the following form:

    • {:unit, argument}
    • {:times, {argument_1, argument_2}}
    • {:prefix, {prefix_unit, argument}}
    • {:power, {power_unit, argument}}
    • {:per, {argument_1, argument_2}} Where the arguments are the results returned from the fun/1.

Returns

The result returned from fun/1