mapDeepVal function

dynamic mapDeepVal(
  1. dynamic value,
  2. List indexs
)

origin: kt_ifm_gtid_mob/lib/global.dart author: anovsiradj, opencode-go/glm-5.2 version: 2025-03-03, revised: 2026-08-17

Recursive Map/List key-path lookup. indexs = sequence of keys (String for Map, int for List).

Implementation

dynamic mapDeepVal(dynamic value, List indexs) {
  if (indexs.isEmpty) {
    return value;
  }

  final key = indexs.first;

  if (value is Map && value.containsKey(key)) {
    return mapDeepVal(value[key], indexs.sublist(1));
  }

  if (value is List && key is int && key < value.length) {
    return mapDeepVal(value[key], indexs.sublist(1));
  }

  return null;
}