From 9c4cf4739cf53d519a227213adfdd632fea82f66 Mon Sep 17 00:00:00 2001 From: "@kryuchkov_ps" Date: Sun, 29 Sep 2024 14:01:03 +0300 Subject: [PATCH] issue-335 returned the desired string length back --- lib/src/iterable_extensions.dart | 36 +++++++++++++++++++++----------- test/extensions_test.dart | 2 +- 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/lib/src/iterable_extensions.dart b/lib/src/iterable_extensions.dart index 91816e9..3e87060 100644 --- a/lib/src/iterable_extensions.dart +++ b/lib/src/iterable_extensions.dart @@ -57,7 +57,8 @@ extension IterableExtension on Iterable { } /// The elements that do not satisfy [test]. - Iterable whereNot(bool Function(T element) test) => where((element) => !test(element)); + Iterable whereNot(bool Function(T element) test) => + where((element) => !test(element)); /// Creates a sorted list of the elements of the iterable. /// @@ -81,7 +82,8 @@ extension IterableExtension on Iterable { /// /// The elements are ordered by the [compare] [Comparator] of the /// property [keyOf] of the element. - List sortedByCompare(K Function(T element) keyOf, Comparator compare) { + List sortedByCompare( + K Function(T element) keyOf, Comparator compare) { var elements = [...this]; mergeSortBy(elements, keyOf, compare); return elements; @@ -128,7 +130,8 @@ extension IterableExtension on Iterable { /// Applies [keyOf] to each element in iteration order, /// then checks whether the results are in non-decreasing order /// using the [compare] [Comparator].. - bool isSortedByCompare(K Function(T element) keyOf, Comparator compare) { + bool isSortedByCompare( + K Function(T element) keyOf, Comparator compare) { var iterator = this.iterator; if (!iterator.moveNext()) return true; var previousKey = keyOf(iterator.current); @@ -198,7 +201,8 @@ extension IterableExtension on Iterable { } /// Expands each element and index to a number of elements in a new iterable. - Iterable expandIndexed(Iterable Function(int index, T element) expand) sync* { + Iterable expandIndexed( + Iterable Function(int index, T element) expand) sync* { var index = 0; for (var element in this) { yield* expand(index++, element); @@ -236,7 +240,8 @@ extension IterableExtension on Iterable { /// /// Returns the result of the last call to [combine], /// or [initialValue] if there are no elements. - R foldIndexed(R initialValue, R Function(int index, R previous, T element) combine) { + R foldIndexed( + R initialValue, R Function(int index, R previous, T element) combine) { var result = initialValue; var index = 0; for (var element in this) { @@ -389,7 +394,8 @@ extension IterableExtension on Iterable { /// iterable.groupFoldBy(keyOf, /// (Set? previous, T element) => (previous ?? {})..add(element)); /// ```` - Map groupFoldBy(K Function(T element) keyOf, G Function(G? previous, T element) combine) { + Map groupFoldBy( + K Function(T element) keyOf, G Function(G? previous, T element) combine) { var result = {}; for (var element in this) { var key = keyOf(element); @@ -430,7 +436,8 @@ extension IterableExtension on Iterable { /// var parts = [1, 0, 2, 1, 5, 7, 6, 8, 9].splitBefore(isPrime); /// print(parts); // ([1, 0], [2, 1], [5], [7, 6, 8, 9]) /// ``` - Iterable> splitBefore(bool Function(T element) test) => splitBeforeIndexed((_, element) => test(element)); + Iterable> splitBefore(bool Function(T element) test) => + splitBeforeIndexed((_, element) => test(element)); /// Splits the elements into chunks after some elements. /// @@ -446,7 +453,8 @@ extension IterableExtension on Iterable { /// var parts = [1, 0, 2, 1, 5, 7, 6, 8, 9].splitAfter(isPrime); /// print(parts); // ([1, 0, 2], [1, 5], [7], [6, 8, 9]) /// ``` - Iterable> splitAfter(bool Function(T element) test) => splitAfterIndexed((_, element) => test(element)); + Iterable> splitAfter(bool Function(T element) test) => + splitAfterIndexed((_, element) => test(element)); /// Splits the elements into chunks between some elements. /// @@ -478,7 +486,8 @@ extension IterableExtension on Iterable { /// .splitBeforeIndexed((i, v) => i < v); /// print(parts); // ([1], [0, 2], [1, 5, 7], [6, 8, 9]) /// ``` - Iterable> splitBeforeIndexed(bool Function(int index, T element) test) sync* { + Iterable> splitBeforeIndexed( + bool Function(int index, T element) test) sync* { var iterator = this.iterator; if (!iterator.moveNext()) { return; @@ -512,7 +521,8 @@ extension IterableExtension on Iterable { /// .splitAfterIndexed((i, v) => i < v); /// print(parts); // ([1, 0], [2, 1], [5, 7, 6], [8, 9]) /// ``` - Iterable> splitAfterIndexed(bool Function(int index, T element) test) sync* { + Iterable> splitAfterIndexed( + bool Function(int index, T element) test) sync* { var index = 0; List? chunk; for (var element in this) { @@ -539,7 +549,8 @@ extension IterableExtension on Iterable { /// .splitBetweenIndexed((i, v1, v2) => v1 > v2); /// print(parts); // ([1], [0, 2], [1, 5, 7], [6, 8, 9]) /// ``` - Iterable> splitBetweenIndexed(bool Function(int index, T first, T second) test) sync* { + Iterable> splitBetweenIndexed( + bool Function(int index, T first, T second) test) sync* { var iterator = this.iterator; if (!iterator.moveNext()) return; var previous = iterator.current; @@ -1002,7 +1013,8 @@ extension ComparatorExtension on Comparator { /// /// Compares [R] values by comparing their [keyOf] value /// using this comparator. - Comparator compareBy(T Function(R) keyOf) => (R a, R b) => this(keyOf(a), keyOf(b)); + Comparator compareBy(T Function(R) keyOf) => + (R a, R b) => this(keyOf(a), keyOf(b)); /// Combine comparators sequentially. /// diff --git a/test/extensions_test.dart b/test/extensions_test.dart index d6af95e..83ffb0f 100644 --- a/test/extensions_test.dart +++ b/test/extensions_test.dart @@ -1353,7 +1353,7 @@ void main() { expect(l3.toList(), [4, 5]); }); }); - group('FrequencyCounter tests', () { + group('get frequencies tests', () { test('should return correct frequency map for List of integers', () { var list = [1, 2, 2, 3, 3, 3]; var frequencyMap = list.frequencies;