transformJsonList<T> function Null safety

List<T> transformJsonList<T>(
  1. List json,
  2. T transform(
    1. Map<String, dynamic>
    )
)

Implementation

List<T> transformJsonList<T>(
  List<dynamic> json,
  T Function(Map<String, dynamic>) transform,
) {
  T mapper(it) {
    try {
      return transform(it as Map<String, dynamic>);
    } on Exception catch (e) {
      throw SchemeConsistencyException(
        'Failed to transform value "$it";\ncause: $e',
      );
    }
  }

  return json.isEmpty ? [] : json.map(mapper).toList();
}