toMap<K, V> static method

Map<K, V> toMap<K, V>(
  1. dynamic map,
  2. NitriteMapper nitriteMapper
)

Converts a map of Documents to a map of key value pair.

Implementation

static Map<K, V> toMap<K, V>(dynamic map, NitriteMapper nitriteMapper) {
  var resultMap = <K, V>{};
  if (map is Map) {
    for (var item in map.entries) {
      var key = nitriteMapper.tryConvert<K, dynamic>(item.key);
      var v = item.value;

      if (v is Iterable && v is! Document) {
        var value = toList(v, nitriteMapper);
        resultMap[key] = value as V;
      } else if (v is Map) {
        var map = toMap(v, nitriteMapper);
        resultMap[key] = map as V;
      } else {
        var value = nitriteMapper.tryConvert<V, dynamic>(item.value);
        if (key != null) {
          resultMap[key] = value as V;
        }
      }
    }
  }
  return resultMap;
}