From 4d3102ffd8befe14ccc13b902f8f6d35598a1c6c Mon Sep 17 00:00:00 2001 From: Simon Leier Date: Mon, 29 Nov 2021 23:46:58 +0100 Subject: [PATCH 1/6] Bump to 1.0 --- CHANGELOG.md | 4 ++++ README.md | 22 ---------------------- lib/src/function.dart | 6 ------ lib/src/string.dart | 12 ------------ pubspec.yaml | 2 +- test/function_test.dart | 9 --------- test/string_test.dart | 9 --------- 7 files changed, 5 insertions(+), 59 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dd113c6..f4227ee 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 1.0.0 +- Promote to stable version +- Remove deprecated extensions + ## 0.8.0 - [PR-136](https://github.com/leisim/dartx/pull/136) New: Multiple extensions for `Map`. `all()`, `any()`, `count()`, `filter()`, `filterKeys()`, `filterNot`, `filterValues`, `getOrElse()`, `mapEntries()`, `mapKeys()`, `mapValues()`, `maxBy()`, `maxWith()`, `minBy()`, `minWith`, `none()`, `toList()`, `toMap()`, `orEmpty()` diff --git a/README.md b/README.md index 85b5251..1722ed9 100644 --- a/README.md +++ b/README.md @@ -104,16 +104,6 @@ final word = 'abcd'.capitalize(); // Abcd final anotherWord = 'Abcd'.capitalize(); // Abcd ``` -### .chars - DEPRECATED - -Use `.characters` from the official characters package. - -Get a list of single character strings from a string. Supports emojis. - -```dart -final chars = 'family๐Ÿ‘จโ€๐Ÿ‘จโ€๐Ÿ‘งโ€๐Ÿ‘ฆ'.chars; // ['f', 'a', 'm', 'i', 'l', 'y', '๐Ÿ‘จโ€๐Ÿ‘จโ€๐Ÿ‘งโ€๐Ÿ‘ฆ'] -``` - ### .decapitalize Returns a copy of the string having its first letter lowercased, or the original string, if it's empty or already starts with a lower case letter. @@ -366,18 +356,6 @@ for (final i in 10.rangeTo(2).step(2)) { ## Function -### .invoke() - DEPRECATED - -Use `call()` instead. This is very useful for `null` checks. - -```dart -final func = (String value) { - print(value); -} - -func?.call('hello world'); -``` - ### .partial(), .partial2() ... Applies some of the required arguments to a function and returns a function which takes the remaining arguments. diff --git a/lib/src/function.dart b/lib/src/function.dart index c0bd209..9b00da3 100644 --- a/lib/src/function.dart +++ b/lib/src/function.dart @@ -6,12 +6,6 @@ typedef Function2 = R Function(A a, B b); typedef Function3 = R Function(A a, B b, C c); typedef Function4 = R Function(A a, B b, C c, D d); -extension Function0InvokeExtension on Function0 { - /// Invokes this function and returns it's return value. - @Deprecated('Use `call()`') - R invoke() => this(); -} - extension Function1InvokeExtensions on Function1 { /// Invokes this function and returns it's return value. R invoke(A first) => this(first); diff --git a/lib/src/string.dart b/lib/src/string.dart index 9ab6525..47fa254 100644 --- a/lib/src/string.dart +++ b/lib/src/string.dart @@ -3,18 +3,6 @@ part of dartx; const _ascii = 0x007f; const _latin1 = 0x00ff; -extension StringCharsExtension on String { - /// The characters of a string. - /// - /// A character is a Unicode Grapheme cluster represented by a substring of - /// the original string. - /// - /// Please use [StringCharacters].characters - /// https://github.com/dart-lang/characters/blob/10527437926f1b454edf9912fe700aa2506b1c3d/lib/src/extensions.dart#L9 - @Deprecated('Use .characters from the official characters package') - Iterable get chars => characters.Characters(this); -} - extension StringCapitalizeExtension on String { /// Returns a copy of this string having its first letter uppercased, or the /// original string, if it's empty or already starts with an upper case diff --git a/pubspec.yaml b/pubspec.yaml index 7f7f9f0..6da749b 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: dartx description: Superpowers for Dart. Collection of useful static extension methods. -version: 0.8.0 +version: 1.0.0 homepage: https://github.com/leisim/dartx environment: diff --git a/test/function_test.dart b/test/function_test.dart index 3c9b5ab..649cc01 100644 --- a/test/function_test.dart +++ b/test/function_test.dart @@ -4,15 +4,6 @@ import 'package:test/test.dart'; void main() { group('Function', () { - group('Function0X', () { - final func = () => 5; - - test('.invoke', () { - // ignore: deprecated_member_use_from_same_package - expect(func.invoke(), 5); - }); - }); - group('Function1X', () { final func = (String s) => s; diff --git a/test/string_test.dart b/test/string_test.dart index 26d8147..6a5aed5 100644 --- a/test/string_test.dart +++ b/test/string_test.dart @@ -5,15 +5,6 @@ import 'package:test/test.dart'; void main() { group('StringX', () { - test('.chars', () { - // ignore: deprecated_member_use_from_same_package - expect('test12'.chars, ['t', 'e', 's', 't', '1', '2']); - expect('test12'.characters, ['t', 'e', 's', 't', '1', '2']); - // ignore: deprecated_member_use_from_same_package - expect('เดโŒ›๏ค™ะ‘๐Ÿ‘จโ€๐Ÿ‘จโ€๐Ÿ‘งโ€๐Ÿ‘ฆ'.chars, ['เด', 'โŒ›', '๏ค™', 'ะ‘', '๐Ÿ‘จโ€๐Ÿ‘จโ€๐Ÿ‘งโ€๐Ÿ‘ฆ']); - expect('เดโŒ›๏ค™ะ‘๐Ÿ‘จโ€๐Ÿ‘จโ€๐Ÿ‘งโ€๐Ÿ‘ฆ'.characters, ['เด', 'โŒ›', '๏ค™', 'ะ‘', '๐Ÿ‘จโ€๐Ÿ‘จโ€๐Ÿ‘งโ€๐Ÿ‘ฆ']); - }); - test('.capitalize()', () { expect(''.capitalize(), ''); expect('123'.capitalize(), '123'); From ab7b5ad35e8e3d7302e41d83df08683a04f59e53 Mon Sep 17 00:00:00 2001 From: David LJ Date: Fri, 17 Dec 2021 11:25:48 +0100 Subject: [PATCH 2/6] refactor: iterable extension Forth -> Fourth --- lib/src/iterable.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/iterable.dart b/lib/src/iterable.dart index 1b17168..e9b1704 100644 --- a/lib/src/iterable.dart +++ b/lib/src/iterable.dart @@ -18,7 +18,7 @@ extension IterableThirdItem on Iterable { E get third => elementAt(2); } -extension IterableForthItem on Iterable { +extension IterableFourthItem on Iterable { /// Fourth element. /// /// ```dart From 430cb04d27bd857a2cd7d3a3191ffa5d33200dd9 Mon Sep 17 00:00:00 2001 From: Konstantin Pelz Date: Tue, 21 Dec 2021 11:47:51 +0100 Subject: [PATCH 3/6] #150 add String.isNullOrBlank and String.isNotNullOrBlank --- README.md | 24 ++++++++++++++++++++++++ lib/src/string.dart | 10 ++++++++++ test/string_test.dart | 16 ++++++++++++++++ 3 files changed, 50 insertions(+) diff --git a/README.md b/README.md index 1722ed9..8148a50 100644 --- a/README.md +++ b/README.md @@ -207,6 +207,30 @@ final isBlank = ' '.isNullOrEmpty; // false final isLineBreak = '\n'.isNullOrEmpty; // false ``` +### .isNullOrBlank + +Returns `true` if the String is either `null` or blank. + +```dart +final isNull = null.isNullOrBlank; // true +final isEmpty = ''.isNullOrBlank; // true +final isBlank = ' '.isNullOrBlank; // true +final isLineBreak = '\n'.isNullOrBlank; // true +final isFoo = ' foo '.isNullOrBlank; // false +``` + +### .isNotNullOrBlank + +Returns `true` if the String is neither `null` nor blank. + +```dart +final isNull = null.isNullOrBlank; // true +final isEmpty = ''.isNullOrBlank; // true +final isBlank = ' '.isNullOrBlank; // true +final isLineBreak = '\n'.isNullOrBlank; // true +final isFoo = ' foo '.isNullOrBlank; // true +``` + ### .isUpperCase Returns `true` if the entire string is upper case. diff --git a/lib/src/string.dart b/lib/src/string.dart index 47fa254..1f2d561 100644 --- a/lib/src/string.dart +++ b/lib/src/string.dart @@ -254,3 +254,13 @@ extension NullableStringIsNotNullOrEmptyExtension on String? { /// Returns `true` if the string is neither null nor empty. bool get isNotNullOrEmpty => !isNullOrEmpty; } + +extension NullableStringIsNullOrBlankExtension on String? { + /// Returns `true` if the string is either `null` or blank. + bool get isNullOrBlank => this?.isBlank ?? true; +} + +extension NullableStringIsNotNullOrBlankExtension on String? { + /// Returns `true` if the string is neither null nor blank. + bool get isNotNullOrBlank => !isNullOrBlank; +} diff --git a/test/string_test.dart b/test/string_test.dart index 6a5aed5..a2d0e49 100644 --- a/test/string_test.dart +++ b/test/string_test.dart @@ -161,6 +161,22 @@ void main() { expect('\n'.isNotNullOrEmpty, true); }); + test('.isNullOrBlank', () { + expect(null.isNullOrBlank, true); + expect(''.isNullOrBlank, true); + expect(' '.isNullOrBlank, true); + expect('\n'.isNullOrBlank, true); + expect(' foo '.isNullOrBlank, false); + }); + + test('.isNotNullOrBlank', () { + expect(null.isNotNullOrBlank, false); + expect(''.isNotNullOrBlank, false); + expect(' '.isNotNullOrBlank, false); + expect('\n'.isNotNullOrBlank, false); + expect(' foo '.isNotNullOrBlank, true); + }); + test('.toUtf8()', () { expect(''.toUtf8(), []); expect('hello'.toUtf8(), [104, 101, 108, 108, 111]); From c26758d04fdeeaafdaa6db20412fe9a09b1577fe Mon Sep 17 00:00:00 2001 From: Biplab Dutta Date: Sat, 5 Mar 2022 00:31:52 +0545 Subject: [PATCH 4/6] feat: obtain an ordinal number of type String for any integer (#153) --- README.md | 11 +++++++++++ lib/dartx.dart | 1 + lib/src/int.dart | 29 +++++++++++++++++++++++++++++ test/int_test.dart | 27 +++++++++++++++++++++++++++ 4 files changed, 68 insertions(+) create mode 100644 lib/src/int.dart create mode 100644 test/int_test.dart diff --git a/README.md b/README.md index 1722ed9..4b973d0 100644 --- a/README.md +++ b/README.md @@ -93,6 +93,17 @@ final increasingSubSequences = list.chunkWhile((a, b) => a + 1 == b); `splitWhen` is the opposite of `chunkWhile` that starts a new chunk every time the predicate _didn't_ match. +## int + +### .ordinal + +Returns an ordinal number of `String` type for any integer + +```dart +final a = 1.ordinal(); // 1st +final b = 108.ordinal(); // 108th +``` + ## String ### .capitalize diff --git a/lib/dartx.dart b/lib/dartx.dart index 4966351..4b59fe3 100644 --- a/lib/dartx.dart +++ b/lib/dartx.dart @@ -17,6 +17,7 @@ part 'src/arithmetic.dart'; part 'src/comparable.dart'; part 'src/comparator.dart'; part 'src/function.dart'; +part 'src/int.dart'; part 'src/iterable.dart'; part 'src/iterable_num.dart'; part 'src/list.dart'; diff --git a/lib/src/int.dart b/lib/src/int.dart new file mode 100644 index 0000000..2fdb3bb --- /dev/null +++ b/lib/src/int.dart @@ -0,0 +1,29 @@ +part of dartx; + +extension Ordinals on T { + /// Returns an ordinal number of `String` type for any integer + /// + /// ```dart + /// 101.ordinal(); // 101st + /// + /// 999218.ordinal(); // 999218th + /// ``` + String ordinal() { + final onesPlace = this % 10; + final tensPlace = ((this / 10).floor()) % 10; + if (tensPlace == 1) { + return '${this}th'; + } else { + switch (onesPlace) { + case 1: + return '${this}st'; + case 2: + return '${this}nd'; + case 3: + return '${this}rd'; + default: + return '${this}th'; + } + } + } +} diff --git a/test/int_test.dart b/test/int_test.dart new file mode 100644 index 0000000..9fac7bd --- /dev/null +++ b/test/int_test.dart @@ -0,0 +1,27 @@ +import 'package:dartx/dartx.dart'; +import 'package:test/test.dart'; + +void main() { + group( + 'intX', + () { + test( + '.ordinal()', + () { + expect(0.ordinal(), '0th'); + expect(1.ordinal(), '1st'); + expect(2.ordinal(), '2nd'); + expect(3.ordinal(), '3rd'); + expect(4.ordinal(), '4th'); + expect(10.ordinal(), '10th'); + expect(101.ordinal(), '101st'); + expect(102.ordinal(), '102nd'); + expect(103.ordinal(), '103rd'); + expect(111.ordinal(), '111th'); + expect(112.ordinal(), '112th'); + expect(113.ordinal(), '113th'); + }, + ); + }, + ); +} From 7acc45f6965d4c2486338448057617896d291737 Mon Sep 17 00:00:00 2001 From: Pascal Welsch Date: Fri, 4 Mar 2022 20:08:59 +0100 Subject: [PATCH 5/6] Make SortedList a public API It is exposed so it should be public. (Constructor is private anyways) --- lib/src/iterable.dart | 12 ++++++------ lib/src/sorted_list.dart | 18 +++++++++--------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/lib/src/iterable.dart b/lib/src/iterable.dart index 1b17168..efac6a6 100644 --- a/lib/src/iterable.dart +++ b/lib/src/iterable.dart @@ -277,8 +277,8 @@ extension IterableSortedBy on Iterable { /// /// **Note:** The actual sorting is performed when an element is accessed for /// the first time. - _SortedList sortedBy(Comparable Function(E element) selector) { - return _SortedList._withSelector(this, selector, 1, null); + SortedList sortedBy(Comparable Function(E element) selector) { + return SortedList._withSelector(this, selector, 1, null); } } @@ -292,8 +292,8 @@ extension IterableSortedByDescending on Iterable { /// /// **Note:** The actual sorting is performed when an element is accessed for /// the first time. - _SortedList sortedByDescending(Comparable Function(E element) selector) { - return _SortedList._withSelector(this, selector, -1, null); + SortedList sortedByDescending(Comparable Function(E element) selector) { + return SortedList._withSelector(this, selector, -1, null); } } @@ -306,8 +306,8 @@ extension IterableSortedWith on Iterable { /// /// **Note:** The actual sorting is performed when an element is accessed for /// the first time. - _SortedList sortedWith(Comparator comparator) { - return _SortedList._(this, comparator); + SortedList sortedWith(Comparator comparator) { + return SortedList._(this, comparator); } } diff --git a/lib/src/sorted_list.dart b/lib/src/sorted_list.dart index 2a705ed..2e24765 100644 --- a/lib/src/sorted_list.dart +++ b/lib/src/sorted_list.dart @@ -12,17 +12,17 @@ Comparator _getComparator( return parent?.compose(newComparator) ?? newComparator; } -class _SortedList extends _DelegatingList { +class SortedList extends _DelegatingList { final Iterable _source; final Comparator _comparator; List? _sortedResults; - _SortedList._( + SortedList._( this._source, this._comparator, ); - _SortedList._withSelector( + SortedList._withSelector( this._source, Comparable Function(E element) selector, int order, @@ -44,8 +44,8 @@ class _SortedList extends _DelegatingList { /// /// **Note:** The actual sorting is performed when an element is accessed for /// the first time. - _SortedList thenBy(Comparable Function(E element) selector) { - return _SortedList._withSelector(this, selector, 1, _comparator); + SortedList thenBy(Comparable Function(E element) selector) { + return SortedList._withSelector(this, selector, 1, _comparator); } /// Returns a new list with all elements sorted according to previously @@ -54,8 +54,8 @@ class _SortedList extends _DelegatingList { /// /// **Note:** The actual sorting is performed when an element is accessed for /// the first time. - _SortedList thenByDescending(Comparable Function(E element) selector) { - return _SortedList._withSelector(this, selector, -1, _comparator); + SortedList thenByDescending(Comparable Function(E element) selector) { + return SortedList._withSelector(this, selector, -1, _comparator); } /// Returns a new list with all elements sorted according to previously @@ -63,8 +63,8 @@ class _SortedList extends _DelegatingList { /// /// **Note:** The actual sorting is performed when an element is accessed for /// the first time. - _SortedList thenWith(Comparator comparator) { - return _SortedList._(this, _comparator.compose(comparator)); + SortedList thenWith(Comparator comparator) { + return SortedList._(this, _comparator.compose(comparator)); } @override From c4314bc0897818e3902368494f92cbd35dfbaf79 Mon Sep 17 00:00:00 2001 From: Pascal Welsch Date: Fri, 4 Mar 2022 20:09:10 +0100 Subject: [PATCH 6/6] Use isEven/isOdd --- test/iterable_test.dart | 40 +++++++++++++++++++------------------- test/map_test.dart | 2 +- test/range_test.dart | 4 ++-- test/sorted_list_test.dart | 8 ++++---- 4 files changed, 27 insertions(+), 27 deletions(-) diff --git a/test/iterable_test.dart b/test/iterable_test.dart index 1017278..f43cc6c 100644 --- a/test/iterable_test.dart +++ b/test/iterable_test.dart @@ -178,7 +178,8 @@ void main() { expect(list1.contentEquals(list2.toList()), false); expect(list1.contentEquals(list2), false); - bool compareCodeUnits(e1, e2) => e1.codeUnitAt(0) == e2.codeUnitAt(0); + bool compareCodeUnits(String e1, String e2) => + e1.codeUnitAt(0) == e2.codeUnitAt(0); expect(list1.contentEquals(list2, compareCodeUnits), true); expect(list3.contentEquals(list4), false); expect(list4.contentEquals(list3), false); @@ -370,7 +371,7 @@ void main() { }); test('.filterIndexed()', () { - final result = [6, 5, 4, 3, 2, 1, 0].filter((it) => it % 2 == 0); + final result = [6, 5, 4, 3, 2, 1, 0].filter((it) => it.isEven); expect(result, [6, 4, 2, 0]); }); @@ -387,7 +388,7 @@ void main() { test('.filterTo()', () { final list = []; - [1, 2, 3, 4, 3, 2, 1].filterTo(list, (e) => e % 2 == 0); + [1, 2, 3, 4, 3, 2, 1].filterTo(list, (e) => e.isEven); expect(list, [2, 4, 2]); }); @@ -396,13 +397,13 @@ void main() { final list = []; [1, 2, 3, 4, 3, 2, 1].filterIndexedTo(list, (e, i) { expect(index++, i); - return e % 2 == 0; + return e.isEven; }); expect(list, [2, 4, 2]); }); test('.filterNot()', () { - expect([1, 2, 3, 4, 3, 2, 1].filterNot((e) => e % 2 == 0), [1, 3, 3, 1]); + expect([1, 2, 3, 4, 3, 2, 1].filterNot((e) => e.isEven), [1, 3, 3, 1]); }); test('.filterNotIndexed()', () { @@ -410,7 +411,7 @@ void main() { expect( [1, 2, 3, 4, 3, 2, 1].filterNotIndexed((e, i) { expect(index++, i); - return e % 2 == 0; + return e.isEven; }), [1, 3, 3, 1], ); @@ -418,7 +419,7 @@ void main() { test('.filterNotTo()', () { final list = []; - [1, 2, 3, 4, 3, 2, 1].filterNotTo(list, (e) => e % 2 == 0); + [1, 2, 3, 4, 3, 2, 1].filterNotTo(list, (e) => e.isEven); expect(list, [1, 3, 3, 1]); }); @@ -427,7 +428,7 @@ void main() { final list = []; [1, 2, 3, 4, 3, 2, 1].filterNotToIndexed(list, (e, i) { expect(index++, i); - return e % 2 == 0; + return e.isEven; }); expect(list, [1, 3, 3, 1]); }); @@ -449,7 +450,7 @@ void main() { test('.whereTo()', () { final list = []; - [1, 2, 3, 4, 3, 2, 1].whereTo(list, (e) => e % 2 == 0); + [1, 2, 3, 4, 3, 2, 1].whereTo(list, (e) => e.isEven); expect(list, [2, 4, 2]); }); @@ -458,13 +459,13 @@ void main() { final list = []; [1, 2, 3, 4, 3, 2, 1].whereIndexedTo(list, (e, i) { expect(index++, i); - return e % 2 == 0; + return e.isEven; }); expect(list, [2, 4, 2]); }); test('.whereNot()', () { - expect([1, 2, 3, 4, 3, 2, 1].whereNot((e) => e % 2 == 0), [1, 3, 3, 1]); + expect([1, 2, 3, 4, 3, 2, 1].whereNot((e) => e.isEven), [1, 3, 3, 1]); }); test('.whereNotIndexed()', () { @@ -472,7 +473,7 @@ void main() { expect( [1, 2, 3, 4, 3, 2, 1].whereNotIndexed((e, i) { expect(index++, i); - return e % 2 == 0; + return e.isEven; }), [1, 3, 3, 1], ); @@ -480,7 +481,7 @@ void main() { test('.whereNotTo()', () { final list = []; - [1, 2, 3, 4, 3, 2, 1].whereNotTo(list, (e) => e % 2 == 0); + [1, 2, 3, 4, 3, 2, 1].whereNotTo(list, (e) => e.isEven); expect(list, [1, 3, 3, 1]); }); @@ -489,7 +490,7 @@ void main() { final list = []; [1, 2, 3, 4, 3, 2, 1].whereNotToIndexed(list, (e, i) { expect(index++, i); - return e % 2 == 0; + return e.isEven; }); expect(list, [1, 3, 3, 1]); }); @@ -506,7 +507,7 @@ void main() { expect([].mapNotNull((it) => 1), []); expect([1, 2, 3, 4].mapNotNull((it) => null), []); expect( - [1, 2, 3, 4].mapNotNull((it) => it % 2 == 0 ? it * 2 : null), + [1, 2, 3, 4].mapNotNull((it) => it.isEven ? it * 2 : null), [4, 8], ); }); @@ -519,7 +520,7 @@ void main() { ); expect([5, 4, null, 2].mapIndexed((index, it) => index), [0, 1, 2, 3]); expect( - [1, 2, 3, 4].mapIndexed((index, it) => it % 2 == 0 ? it * 2 : null), + [1, 2, 3, 4].mapIndexed((index, it) => it.isEven ? it * 2 : null), [null, 4, null, 8], ); }); @@ -533,7 +534,7 @@ void main() { ); expect( [1, 2, 3, 4] - .mapIndexedNotNull((index, it) => it % 2 == 0 ? it * 2 : null), + .mapIndexedNotNull((index, it) => it.isEven ? it * 2 : null), [4, 8], ); }); @@ -925,8 +926,7 @@ void main() { test('groupBy', () { expect( - ['foo', 'bar', 'baz', 'bop', 'qux'] - .groupBy((dynamic string) => string[1]), + ['foo', 'bar', 'baz', 'bop', 'qux'].groupBy((it) => it[1]), equals({ 'o': ['foo', 'bop'], 'a': ['bar', 'baz'], @@ -937,7 +937,7 @@ void main() { test('.partition()', () { expect([].partition((it) => false), >[[], []]); - expect([1, 2, 3, 4, 5, 6].partition((it) => it % 2 == 1), [ + expect([1, 2, 3, 4, 5, 6].partition((it) => it.isOdd), [ [1, 3, 5], [2, 4, 6] ]); diff --git a/test/map_test.dart b/test/map_test.dart index 6777876..f8f9810 100644 --- a/test/map_test.dart +++ b/test/map_test.dart @@ -60,7 +60,7 @@ void main() { test('count even', () { final map = {1: 'a', 2: 'b', 3: 'c'}; - expect(map.count((it) => it.key % 2 == 0), 1); + expect(map.count((it) => it.key.isEven), 1); }); }); diff --git a/test/range_test.dart b/test/range_test.dart index 3d0bc73..9ce6064 100644 --- a/test/range_test.dart +++ b/test/range_test.dart @@ -316,7 +316,7 @@ void main() { }); test('lastWhere', () { final range = IntProgression(0, 9, step: 3); - bool isEven(it) => it % 2 == 0; + bool isEven(int it) => it.isEven; expect(range.last, 9); expect(range.lastWhere(isEven), 6); }); @@ -347,7 +347,7 @@ void main() { }); test('firstWhere minds the predicate', () { final range = IntProgression(1, 10, step: 3); - bool isEven(it) => it % 2 == 0; + bool isEven(int it) => it.isEven; expect(range.first, 1); expect(range.firstWhere(isEven), 4); }); diff --git a/test/sorted_list_test.dart b/test/sorted_list_test.dart index 4643012..5242949 100644 --- a/test/sorted_list_test.dart +++ b/test/sorted_list_test.dart @@ -43,7 +43,7 @@ void main() { expect(_sortedList.firstWhere((it) => it.isEven), 2); }); test('fold', () { - expect(_sortedList.fold(0, (dynamic a, b) => a + b), 10); + expect(_sortedList.fold(0, (int a, b) => a + b), 10); }); test('followedBy', () { expect(_sortedList.followedBy([2]), [1, 2, 3, 4, 2]); @@ -108,7 +108,7 @@ void main() { expect(_sortedList.toSet(), {1, 2, 3, 4}); }); test('where', () { - expect(_sortedList.where((it) => it % 2 == 0), [2, 4]); + expect(_sortedList.where((it) => it.isEven), [2, 4]); }); test('whereType', () { expect(_sortedList.whereType(), [1, 2, 3, 4]); @@ -211,7 +211,7 @@ void main() { }); test('removeWhere', () { final list = _sortedList; - list.removeWhere((it) => it % 2 == 0); + list.removeWhere((it) => it.isEven); expect(list, [1, 3]); }); test('replaceRange', () { @@ -221,7 +221,7 @@ void main() { }); test('retainWhere', () { final list = _sortedList; - list.retainWhere((it) => it % 2 == 0); + list.retainWhere((it) => it.isEven); expect(list, [2, 4]); }); test('reversed', () {