View Source Cldr.List.Pattern (Cldr Lists v2.11.1)

A list pattern drives list formatting and it defines how to combine list elements at the begging, in the middle and at the end of a list. It also has a special pattern used when the list contains only two elements.

Summary

Functions

Creates a new list format.

Types

@type pattern() :: [non_neg_integer() | String.t(), ...]
@type t() :: %Cldr.List.Pattern{
  end: pattern(),
  middle: pattern(),
  start: pattern(),
  two: pattern()
}

Functions

Creates a new list format.

A list pattern consists of four string templates into which list elements are interpolated when formatting.

The four templates are:

  • :start used to format the first two list elements.

  • :middle is used to format elements in the middle of the list.

  • :end is used to format the last two elements in the list.

  • :two is used to format a list if it contains only two elements.

Only the :start option is required. It will be used as the default for any other option that is not provided.

Arguments

  • options is a keyword list of options.

Options

  • :start is a pattern template as a string. This option is required.

  • :middle is a pattern template as a string.

  • :end is a pattern template as a string.

  • :two is a pattern template as a string.

Returns

{:ok, pattern} or

{:error, reason}

Pattern template

A pattern template is a string that contains two placeholders denoted by {0} and {1}.

Example

iex> Cldr.List.Pattern.new(
...>   start: "{0}, {1}"),
...>   middle: "{0}, {1}"),
...>   end: "{0} and {1}"),
...>   two: "{0} and {1}")
...>  )
{:ok, _pattern}