abstract class Mappable<T> {
  Map<String, dynamic> toMap();
}
class MapUtil {
  /// 单个对象 -> Map
  static Map<String, dynamic> toMap<T extends Mappable>(T obj) {
    return obj.toMap();
  }

  /// List<Object> -> List<Map>
  static List<Map<String, dynamic>> toMapList<T extends Mappable>(List<T> list) {
    return list.map((e) => e.toMap()).toList();
  }

  /// Map -> 对象
  static T fromMap<T>(Map<String, dynamic> map, T Function(Map<String, dynamic>) fromMapFunc) {
    return fromMapFunc(map);
  }

  /// List<Map> -> List<Object>
  static List<T> fromMapList<T>(List<Map<String, dynamic>> list, T Function(Map<String, dynamic>) fromMapFunc) {
    return list.map((e) => fromMapFunc(e)).toList();
  }
}