Cldr.List.intersperse
You're seeing just the function
intersperse
, go back to Cldr.List module for more information.
Specs
intersperse([term()], Cldr.backend(), Keyword.t()) :: {:ok, [String.t()]} | {:error, {module(), String.t()}}
Intersperces a list elements into a list format according to the list pattern rules for a locale.
This function can be helpful when creating a list from Phoenix
safe strings which are of the format {:safe, "some string"}
Arguments
list
is any list of of termsoptions
is a keyword list
Options
:locale
is any configured locale. SeeCldr.known_locale_names/1
. The default islocale: Cldr.get_locale/1
:format
is atom returned byCldr.List.known_list_formats/0
. The default is:standard
Examples
iex> Cldr.List.intersperse(["a", "b", "c"], MyApp.Cldr, locale: "en")
{:ok, ["a", ", ", "b", ", and ", "c"]}
iex> Cldr.List.intersperse(["a", "b", "c"], MyApp.Cldr, locale: "en", format: :unit_narrow)
{:ok, ["a", " ", "b", " ", "c"]}
iex> Cldr.List.intersperse(["a", "b", "c"], MyApp.Cldr, locale: "fr")
{:ok, ["a", ", ", "b", " et ", "c"]}
iex> Cldr.List.intersperse([1,2,3,4,5,6], MyApp.Cldr)
{:ok, [1, ", ", 2, ", ", 3, ", ", 4, ", ", 5, ", and ", 6]}
iex> Cldr.List.intersperse(["a"], MyApp.Cldr)
{:ok, ["a"]}
iex> Cldr.List.intersperse([1,2], MyApp.Cldr)
{:ok, [1, " and ", 2]}