LCOV - code coverage report

Current view
top level - src/converters - converter.dart
Test
lcov.info
Date
2024-11-13
Legend
Lines
hit
not hit
Branches
taken
not taken
# not executed
HitTotalCoverage
Lines283093.3%
Functions00-
Branches00-
Each row represents a line of source code
LineBranchHitsSource code
1typedef Cast<T> = T Function(dynamic);
2
3abstract base class Converter {
423 const Converter();
5
66 static bool isIdentity<T>(Cast<T>? cast) =>
76 (cast == null) || (cast == identity<T>);
8
916 static T identity<T>(dynamic x) => x as T;
10
113 static List<dynamic> toList(dynamic x) =>
124 (x is List) ? x : (x as Iterable).toList();
13
140 static Set<dynamic> toSet(dynamic x) =>
150 (x is Set) ? x : (x as Iterable).toSet();
16
17 // non-nullable value
18 Cast<T> value<T>();
19
20 // nullable value
212 Cast<T?> nullable<T>([Cast<T>? cast]) {
222 final op = cast ?? value<T>();
232 return Converter.isIdentity<T>(op)
242 ? value<T?>()
253 : (($) => ($ == null) ? null : op($));
261 }
27
28 // list
293 Cast<List<T>> list<T>([Cast<T>? cast]) {
303 final op = cast ?? value<T>();
313 return Converter.isIdentity<T>(op)
327 ? ((x) => Converter.toList(x).cast<T>())
335 : ((x) => Converter.toList(x).map<T>(op).toList());
341 }
35
36 // set
372 Cast<Set<T>> set<T>([Cast<T>? cast]) {
382 final op = list<T>(cast);
394 return (x) => op(x).toSet();
401 }
41
42 // map
436 Cast<Map<K, V>> map<K, V>({Cast<K>? kcast, Cast<V>? vcast}) {
449 final kop = kcast ?? value<K>(), vop = vcast ?? value<V>();
459 if (Converter.isIdentity<K>(kop) && Converter.isIdentity<V>(vop)) {
469 return ((x) => (x as Map).cast<K, V>());
47 } else {
487 return ((x) => (x as Map).map((k, v) => MapEntry(kop(k), vop(v))));
49 }
503 }
51}
Choose Features