decodeByMultiKeys<T> function

T? decodeByMultiKeys<T>(
  1. Map<String, dynamic> map,
  2. List<String> keys, {
  3. T? transformer(
    1. Object value
    )?,
  4. T orElse()?,
})

Decodes a value from the given map by matching aganist given set of keys.

If any of the keys matches to a value in the map, the value is returned.

Implementation

T? decodeByMultiKeys<T>(
  Map<String, dynamic> map,
  List<String> keys, {
  T? Function(Object value)? transformer,
  T Function()? orElse,
}) {
  for (final key in keys) {
    if (!map.containsKey(key)) {
      continue;
    }

    final value = map[key];

    if (transformer != null) {
      return transformer(value);
    }

    return value;
  }

  return orElse?.call();
}