mirror of
https://gitlab.com/nkming2/nc-photos.git
synced 2025-03-13 18:58:53 +01:00
Util fn to trasform list in-place
This commit is contained in:
parent
f6614a3542
commit
b809809727
1 changed files with 12 additions and 0 deletions
|
@ -1,6 +1,7 @@
|
|||
import 'dart:math' as math;
|
||||
|
||||
import 'package:collection/collection.dart';
|
||||
import 'package:nc_photos/int_extension.dart';
|
||||
|
||||
extension ListExtension<T> on List<T> {
|
||||
Iterable<T> takeIndex(List<int> indexes) => indexes.map((e) => this[e]);
|
||||
|
@ -26,4 +27,15 @@ extension ListExtension<T> on List<T> {
|
|||
void stableSort([int Function(T a, T b)? compare]) {
|
||||
mergeSort(this, compare: compare);
|
||||
}
|
||||
|
||||
/// In-place transform and return this
|
||||
///
|
||||
/// Since the elements are in-place transformed, they have to share the same
|
||||
/// type
|
||||
List<T> transform(T Function(T element) fn) {
|
||||
for (final i in 0.until(length)) {
|
||||
this[i] = fn(this[i]);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue