From 2171c3374e582844d8d2043babb066129e0f35e4 Mon Sep 17 00:00:00 2001 From: Koen Van Looveren Date: Tue, 20 Apr 2021 16:22:19 +0200 Subject: [PATCH] Fixed comments --- lib/src/extension/list_extensions.dart | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/lib/src/extension/list_extensions.dart b/lib/src/extension/list_extensions.dart index 8e64c77..cc72ffa 100644 --- a/lib/src/extension/list_extensions.dart +++ b/lib/src/extension/list_extensions.dart @@ -1,5 +1,3 @@ -import 'package:icapps_architecture/src/extension/iterable_extensions.dart'; - extension ListExtensions on List { ///Replaces all data in the list with [newData] void replaceAll(List newData) { @@ -9,14 +7,13 @@ extension ListExtensions on List { ///Replaces all items that matches where with [newData] void replaceWhere(bool Function(T) where, T newData, {int? count}) { - final whereResult = this.where(where); - whereResult.forEachIndexed((index, result) { - if (count != null && index >= count) return; - if (result == null) return; - final originalIndex = indexOf(result); - removeAt(originalIndex); - insert(originalIndex, newData); - }); + final replaceCount = count ?? length; + final whereResult = this.where(where).toList(); + for (var i = 0; i < whereResult.length; ++i) { + if (i >= replaceCount) break; + final result = whereResult[i]; + this[indexOf(result)] = newData; + } } /// Sorts the list based on the comparable returned by [by]. By default