mergeLocaleLists function

List<Locale> mergeLocaleLists(
  1. Iterable<Locale> first,
  2. Iterable<Locale> second
)

Merges two locale lists without duplicates (first occurrence wins).

Implementation

List<Locale> mergeLocaleLists(Iterable<Locale> first, Iterable<Locale> second) {
  final Set<String> seen = <String>{};
  final List<Locale> out = <Locale>[];
  for (final Locale locale in <Locale>[...first, ...second]) {
    final String key =
        '${locale.languageCode}\u001f${locale.scriptCode ?? ''}\u001f${locale.countryCode ?? ''}';
    if (seen.add(key)) {
      out.add(locale);
    }
  }
  return out;
}