@@ -35,7 +35,7 @@ extension IterableX<E> on Iterable<E> {
35
35
/// ```
36
36
E ? elementAtOrNull (int index) {
37
37
if (index < 0 ) return null ;
38
- int count = 0 ;
38
+ var count = 0 ;
39
39
for (final element in this ) {
40
40
if (index == count++ ) return element;
41
41
}
@@ -65,7 +65,7 @@ extension IterableX<E> on Iterable<E> {
65
65
/// ```
66
66
E elementAtOrElse (int index, E Function (int index) defaultValue) {
67
67
if (index < 0 ) return defaultValue (index);
68
- int count = 0 ;
68
+ var count = 0 ;
69
69
for (final element in this ) {
70
70
if (index == count++ ) return element;
71
71
}
@@ -148,8 +148,8 @@ extension IterableX<E> on Iterable<E> {
148
148
/// If [end] is omitted, it is being set to `lastIndex` .
149
149
List <E > slice (int start, [int end = - 1 ]) {
150
150
final list = this is List ? this as List <E > : toList ();
151
- int _start = start;
152
- int _end = end;
151
+ var _start = start;
152
+ var _end = end;
153
153
154
154
if (_start < 0 ) {
155
155
_start = _start + list.length;
@@ -166,7 +166,7 @@ extension IterableX<E> on Iterable<E> {
166
166
/// Performs the given [action] on each element, providing sequential index
167
167
/// with the element.
168
168
void forEachIndexed (void Function (E element, int index) action) {
169
- int index = 0 ;
169
+ var index = 0 ;
170
170
for (final element in this ) {
171
171
action (element, index++ );
172
172
}
@@ -284,7 +284,7 @@ extension IterableX<E> on Iterable<E> {
284
284
String truncated = '...' ,
285
285
}) {
286
286
final buffer = StringBuffer ();
287
- int count = 0 ;
287
+ var count = 0 ;
288
288
for (final element in this ) {
289
289
if (limit != null && count >= limit) {
290
290
buffer.write (truncated);
@@ -311,7 +311,7 @@ extension IterableX<E> on Iterable<E> {
311
311
/// Returns the sum of all values produced by [selector] function applied to
312
312
/// each element in the collection.
313
313
double sumBy (num Function (E element) selector) {
314
- double sum = 0.0 ;
314
+ var sum = 0.0 ;
315
315
for (final current in this ) {
316
316
sum += selector (current);
317
317
}
@@ -321,7 +321,7 @@ extension IterableX<E> on Iterable<E> {
321
321
/// Returns the average of values returned by [selector] for all elements in
322
322
/// the collection.
323
323
double averageBy (num Function (E element) selector) {
324
- int count = 0 ;
324
+ var count = 0 ;
325
325
num sum = 0 ;
326
326
327
327
for (final current in this ) {
@@ -367,7 +367,7 @@ extension IterableX<E> on Iterable<E> {
367
367
if (! it.moveNext ()) {
368
368
return null ;
369
369
}
370
- E currentMin = it.current;
370
+ var currentMin = it.current;
371
371
372
372
while (it.moveNext ()) {
373
373
if ((it.current as Comparable ).compareTo (currentMin) == order) {
@@ -384,8 +384,8 @@ extension IterableX<E> on Iterable<E> {
384
384
return null ;
385
385
}
386
386
387
- E currentMin = it.current;
388
- Comparable currentMinValue = selector (it.current);
387
+ var currentMin = it.current;
388
+ var currentMinValue = selector (it.current);
389
389
while (it.moveNext ()) {
390
390
final comp = selector (it.current);
391
391
if (comp.compareTo (currentMinValue) == order) {
@@ -402,7 +402,7 @@ extension IterableX<E> on Iterable<E> {
402
402
if (! it.moveNext ()) {
403
403
return null ;
404
404
}
405
- E currentMin = it.current;
405
+ var currentMin = it.current;
406
406
407
407
while (it.moveNext ()) {
408
408
if (comparator (it.current, currentMin) == order) {
@@ -417,7 +417,7 @@ extension IterableX<E> on Iterable<E> {
417
417
///
418
418
/// If no [predicate] is given, this equals to [length] .
419
419
int count ([bool Function (E element)? predicate]) {
420
- int count = 0 ;
420
+ var count = 0 ;
421
421
if (predicate == null ) {
422
422
return length;
423
423
} else {
@@ -543,7 +543,7 @@ extension IterableX<E> on Iterable<E> {
543
543
/// Returns all elements that satisfy the given [predicate] .
544
544
Iterable <E > whereIndexed (
545
545
bool Function (E element, int index) predicate) sync * {
546
- int index = 0 ;
546
+ var index = 0 ;
547
547
for (final element in this ) {
548
548
if (predicate (element, index++ )) {
549
549
yield element;
@@ -565,7 +565,7 @@ extension IterableX<E> on Iterable<E> {
565
565
/// [destination] .
566
566
void whereIndexedTo (
567
567
List <E > destination, bool Function (E element, int index) predicate) {
568
- int index = 0 ;
568
+ var index = 0 ;
569
569
for (final element in this ) {
570
570
if (predicate (element, index++ )) {
571
571
destination.add (element);
@@ -585,7 +585,7 @@ extension IterableX<E> on Iterable<E> {
585
585
/// Returns all elements not matching the given [predicate] .
586
586
Iterable <E > whereNotIndexed (
587
587
bool Function (E element, int index) predicate) sync * {
588
- int index = 0 ;
588
+ var index = 0 ;
589
589
for (final element in this ) {
590
590
if (! predicate (element, index++ )) {
591
591
yield element;
@@ -607,7 +607,7 @@ extension IterableX<E> on Iterable<E> {
607
607
/// [destination] .
608
608
void whereNotToIndexed (
609
609
List <E > destination, bool Function (E element, int index) predicate) {
610
- int index = 0 ;
610
+ var index = 0 ;
611
611
for (final element in this ) {
612
612
if (! predicate (element, index++ )) {
613
613
destination.add (element);
@@ -634,7 +634,7 @@ extension IterableX<E> on Iterable<E> {
634
634
/// given [transform] function to each element and its index in the original
635
635
/// collection.
636
636
Iterable <R > mapIndexed <R >(R Function (int index, E ) transform) sync * {
637
- int index = 0 ;
637
+ var index = 0 ;
638
638
for (final element in this ) {
639
639
yield transform (index++ , element);
640
640
}
@@ -644,7 +644,7 @@ extension IterableX<E> on Iterable<E> {
644
644
/// applying the given [transform] function to each element and its index
645
645
/// in the original collection.
646
646
Iterable <R > mapIndexedNotNull <R >(R ? Function (int index, E ) transform) sync * {
647
- int index = 0 ;
647
+ var index = 0 ;
648
648
for (final element in this ) {
649
649
final result = transform (index++ , element);
650
650
if (result != null ) {
@@ -703,7 +703,7 @@ extension IterableX<E> on Iterable<E> {
703
703
throw ArgumentError ('Requested chunk size $size is less than one.' );
704
704
}
705
705
706
- List < E > currentChunk = [];
706
+ var currentChunk = < E > [];
707
707
for (final current in this ) {
708
708
currentChunk.add (current);
709
709
if (currentChunk.length >= size) {
@@ -731,8 +731,8 @@ extension IterableX<E> on Iterable<E> {
731
731
/// See also:
732
732
/// - [splitWhen] , which works similarly but with a reverted [predicate] .
733
733
Iterable <List <E >> chunkWhile (bool Function (E , E ) predicate) sync * {
734
- List < E > currentChunk = [];
735
- bool hasPrevious = false ;
734
+ var currentChunk = < E > [];
735
+ var hasPrevious = false ;
736
736
late E previous;
737
737
738
738
for (final element in this ) {
@@ -784,8 +784,8 @@ extension IterableX<E> on Iterable<E> {
784
784
}) sync * {
785
785
final gap = step - size;
786
786
if (gap >= 0 ) {
787
- List < E > buffer = [];
788
- int skip = 0 ;
787
+ var buffer = < E > [];
788
+ var skip = 0 ;
789
789
for (final element in this ) {
790
790
if (skip > 0 ) {
791
791
skip -= 1 ;
@@ -794,7 +794,7 @@ extension IterableX<E> on Iterable<E> {
794
794
buffer.add (element);
795
795
if (buffer.length == size) {
796
796
yield buffer;
797
- buffer = [];
797
+ buffer = < E > [];
798
798
skip = gap;
799
799
}
800
800
}
@@ -842,7 +842,7 @@ extension IterableX<E> on Iterable<E> {
842
842
///
843
843
/// If [n] is omitted, the Iterable cycles forever.
844
844
Iterable <E > cycle ([int ? n]) sync * {
845
- Iterator < E > it = iterator;
845
+ var it = iterator;
846
846
if (! it.moveNext ()) {
847
847
return ;
848
848
}
@@ -855,7 +855,7 @@ extension IterableX<E> on Iterable<E> {
855
855
it = iterator;
856
856
}
857
857
} else {
858
- int count = 0 ;
858
+ var count = 0 ;
859
859
yield it.current;
860
860
while (count++ < n) {
861
861
while (it.moveNext ()) {
0 commit comments