import 'package:flutter/foundation.dart';

List<T> _parserList<T>(Map<String, dynamic> args) {
  final list = args['list'] as List<dynamic>;
  final T Function(Map<String, dynamic>) fromJson =
      args['fromJson'] as T Function(Map<String, dynamic>);

  return list.map<T>((e) => fromJson(e as Map<String, dynamic>)).toList();
}

Future<List<T>> parseListInIsolate<T>(
  List<dynamic> list,
  T Function(Map<String, dynamic>) fromJson,
) async {
  return compute(_parserList<T>, {'list': list, 'fromJson': fromJson});
}
