# `Localize.Collation.Reorder`
[🔗](https://github.com/elixir-localize/localize/blob/v0.38.0/lib/localize/collation/reorder.ex#L1)

Script reordering for collation (kr= / reorder option).

Remaps primary weights to change the relative order of scripts.
For example, `reorder: [:Grek, :Latn]` would sort Greek characters
before Latin characters.

# `apply_mapping`

```elixir
@spec apply_mapping((non_neg_integer() -&gt; non_neg_integer()) | nil, non_neg_integer()) ::
  non_neg_integer()
```

Apply a reorder mapping to a primary weight.

### Arguments

* `mapping_fn` - a reorder mapping function from `build_mapping/1`, or `nil`.

* `primary` - the primary weight to remap.

### Returns

The remapped primary weight, or the original if `mapping_fn` is `nil`.

# `build_mapping`

```elixir
@spec build_mapping([atom()]) :: (non_neg_integer() -&gt; non_neg_integer()) | nil
```

Build a reorder mapping function from the given script codes.

### Arguments

* `reorder_codes` - a list of script code atoms (e.g., `[:Grek, :Latn]`).

### Returns

* A function `(primary :: integer()) -> integer()` that remaps primary weights.

* `nil` if the list is empty or no valid mappings were found.

# `load_primary_to_fractional_lead`

```elixir
@spec load_primary_to_fractional_lead() :: %{
  required(integer() | {:sub, integer()}) =&gt; non_neg_integer()
}
```

Load a mapping from allkeys integer primary weights to their
fractional lead bytes and sub-bytes.

### Returns

A map `%{integer() | {:sub, integer()} => non_neg_integer()}`.

# `load_script_ranges`

```elixir
@spec load_script_ranges() :: %{
  required(String.t()) =&gt; {non_neg_integer(), non_neg_integer()}
}
```

Load the script-to-lead-byte-range mapping from FractionalUCA.txt.

### Returns

A map `%{String.t() => {start_byte, end_byte}}`.

---

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