|
1 | 1 | import 'dart:convert'; |
2 | 2 |
|
3 | | -import 'package:collection/collection.dart'; |
4 | | - |
5 | 3 | import '../../codelessly_api.dart'; |
6 | 4 |
|
7 | 5 | /// Declares extensions on [Object]. |
@@ -297,64 +295,56 @@ extension ConversionExt on Object? { |
297 | 295 | if (set == null) return null; |
298 | 296 |
|
299 | 297 | if (R == Set<int>) { |
300 | | - return set |
301 | | - .map<int?>((e) => e?.toInt()) |
302 | | - .whereNotNull() |
303 | | - .toSet() |
304 | | - .tryCast<R>(); |
| 298 | + return set.map<int?>((e) => e?.toInt()).nonNulls.toSet().tryCast<R>(); |
305 | 299 | } |
306 | 300 | if (R == Set<int?>) { |
307 | | - return set.map<int?>((e) => e?.toInt()).toSet().tryCast<R>(); |
| 301 | + return set.map<int?>((e) => e?.toInt()).nonNulls.toSet().tryCast<R>(); |
308 | 302 | } |
309 | 303 | if (R == Set<double>) { |
310 | 304 | return set |
311 | 305 | .map<double?>((e) => e?.toDouble()) |
312 | | - .whereNotNull() |
| 306 | + .nonNulls |
313 | 307 | .toSet() |
314 | 308 | .tryCast<R>(); |
315 | 309 | } |
316 | 310 | if (R == Set<double?>) { |
317 | | - return set.map<double?>((e) => e?.toDouble()).toSet().tryCast<R>(); |
318 | | - } |
319 | | - if (R == Set<num>) { |
320 | 311 | return set |
321 | | - .map<num?>((e) => e?.toNum()) |
322 | | - .whereNotNull() |
| 312 | + .map<double?>((e) => e?.toDouble()) |
| 313 | + .nonNulls |
323 | 314 | .toSet() |
324 | 315 | .tryCast<R>(); |
325 | 316 | } |
| 317 | + if (R == Set<num>) { |
| 318 | + return set.map<num?>((e) => e?.toNum()).nonNulls.toSet().tryCast<R>(); |
| 319 | + } |
326 | 320 | if (R == Set<num?>) { |
327 | | - return set.map<num?>((e) => e?.toNum()).toSet().tryCast<R>(); |
| 321 | + return set.map<num?>((e) => e?.toNum()).nonNulls.toSet().tryCast<R>(); |
328 | 322 | } |
329 | 323 | if (R == Set<bool>) { |
330 | | - return set |
331 | | - .map<bool?>((e) => e?.toBool()) |
332 | | - .whereNotNull() |
333 | | - .toSet() |
334 | | - .tryCast<R>(); |
| 324 | + return set.map<bool?>((e) => e?.toBool()).nonNulls.toSet().tryCast<R>(); |
335 | 325 | } |
336 | 326 | if (R == Set<bool?>) { |
337 | | - return set.map<bool?>((e) => e?.toBool()).toSet().tryCast<R>(); |
| 327 | + return set.map<bool?>((e) => e?.toBool()).nonNulls.toSet().tryCast<R>(); |
338 | 328 | } |
339 | 329 | if (R == Set<String>) { |
340 | 330 | return set |
341 | 331 | .map<String?>((e) => e?.toString()) |
342 | | - .whereNotNull() |
| 332 | + .nonNulls |
343 | 333 | .toSet() |
344 | 334 | .tryCast<R>(); |
345 | 335 | } |
346 | 336 | if (R == Set<String?>) { |
347 | | - return set.map<String?>((e) => e?.toString()).toSet().tryCast<R>(); |
348 | | - } |
349 | | - if (R == Set<Map>) { |
350 | 337 | return set |
351 | | - .map<Map?>((e) => e?.toMap()) |
352 | | - .whereNotNull() |
| 338 | + .map<String?>((e) => e?.toString()) |
| 339 | + .nonNulls |
353 | 340 | .toSet() |
354 | 341 | .tryCast<R>(); |
355 | 342 | } |
| 343 | + if (R == Set<Map>) { |
| 344 | + return set.map<Map?>((e) => e?.toMap()).nonNulls.toSet().tryCast<R>(); |
| 345 | + } |
356 | 346 | if (R == Set<Map?>) { |
357 | | - return set.map<Map?>((e) => e?.toMap()).toSet().tryCast<R>(); |
| 347 | + return set.map<Map?>((e) => e?.toMap()).nonNulls.toSet().tryCast<R>(); |
358 | 348 | } |
359 | 349 |
|
360 | 350 | return set.tryCast<R>(); |
|
0 commit comments