# `Cldr.Substitution`
[🔗](https://github.com/elixir-cldr/cldr/blob/v2.47.3/lib/cldr/substitution.ex#L1)

Compiles substitution formats that are of the form
"{0} something {1}" into a token list that allows for
more efficient parameter substitution at runtime.

# `parse`

```elixir
@spec parse(String.t()) :: [String.t() | integer(), ...] | {:error, String.t()}
```

Parses a substitution template into a list of tokens to
allow efficient parameter substitution at runtime.

* `template` is a binary that may include parameter markers that
are substituted for values at runtime.

Returns:

* A list of tokens where any substitution is marked as an integer
any any binary tokens are passed through as is.

## Examples

    iex> Cldr.Substitution.parse "{0}, {1}"
    [0, ", ", 1]

    iex> Cldr.Substitution.parse "{0} This is something {1} or another {2}"
    [0, " This is something ", 1, " or another ", 2]

This function is primarily intended to support compile-time generation
of templates that simplify and speed up parameter substitution at runtime.

# `substitute`

```elixir
@spec substitute(term() | [term(), ...], [String.t() | integer(), ...]) :: [
  term(),
  ...
]
```

Substitutes a list of values into a template token list that is
created by `Cldr.Substitution.parse/1`.

* `list1` is a list of values that will be substituted into a
a template list previously created by `Cldr.Substitution.parse/1`

* `list2` is a template list previously created by
`Cldr.Substitution.parse/1`

Returns:

* A list with values substituted for parameters in the `list1` template

## Examples:

    iex> template = Cldr.Substitution.parse "{0} This is something {1}"
    [0, " This is something ", 1]
    iex> Cldr.Substitution.substitute ["a", "b"], template
    ["a", " This is something ", "b"]

---

*Consult [api-reference.md](api-reference.md) for complete listing*
