From 59f7bfacee8e45459830a0dd8be416cc9477ef16 Mon Sep 17 00:00:00 2001 From: Oleh Prypin Date: Thu, 25 Jan 2024 21:21:45 +0100 Subject: [PATCH 1/3] Deprecate whereNotNull from IterableNullableExtensions Dart SDK since 3.0 has an exact equivalent extension `nonNulls` in the core. --- CHANGELOG.md | 3 +++ lib/src/iterable_extensions.dart | 1 + 2 files changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e38e1a8..7bed0e7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,9 @@ - Shuffle `IterableExtension.sample` results. - Fix `mergeSort` when the runtime iterable generic is a subtype of the static generic. +- Deprecate `whereNotNull()` from `IterableNullableExtension`. Use `nonNulls` + instead - this is an equivalent extension available in Dart core since + version 3.0. - Require Dart `^3.1.0` - Mark "mixin" classes as `mixin`. diff --git a/lib/src/iterable_extensions.dart b/lib/src/iterable_extensions.dart index 1bf4b3e..0d52fbb 100644 --- a/lib/src/iterable_extensions.dart +++ b/lib/src/iterable_extensions.dart @@ -611,6 +611,7 @@ extension IterableNullableExtension on Iterable { /// of this iterable, in their original iteration order. /// /// For an `Iterable`, this method is equivalent to `.whereType()`. + @Deprecated('Use .nonNulls instead.') Iterable whereNotNull() sync* { for (var element in this) { if (element != null) yield element; From f503c2f0db349b9fcb1f153920c20fc76f799067 Mon Sep 17 00:00:00 2001 From: Oleh Prypin Date: Thu, 25 Jan 2024 21:31:38 +0100 Subject: [PATCH 2/3] Delete tests as well --- test/extensions_test.dart | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/test/extensions_test.dart b/test/extensions_test.dart index 3b1401a..4ba036b 100644 --- a/test/extensions_test.dart +++ b/test/extensions_test.dart @@ -866,23 +866,6 @@ void main() { }); }); }); - group('of nullable', () { - group('.whereNotNull', () { - test('empty', () { - expect(iterable([]).whereNotNull(), isEmpty); - }); - test('single', () { - expect(iterable([null]).whereNotNull(), isEmpty); - expect(iterable([1]).whereNotNull(), [1]); - }); - test('multiple', () { - expect(iterable([1, 3, 5]).whereNotNull(), [1, 3, 5]); - expect(iterable([null, null, null]).whereNotNull(), isEmpty); - expect( - iterable([1, null, 3, null, 5]).whereNotNull(), [1, 3, 5]); - }); - }); - }); group('of number', () { group('.sum', () { test('empty', () { From 339c39dbdd0197e737af1b139062fd2054c0c851 Mon Sep 17 00:00:00 2001 From: Oleh Prypin Date: Fri, 26 Jan 2024 01:16:12 +0100 Subject: [PATCH 3/3] Restore tests but ignore violations --- test/extensions_test.dart | 47 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/test/extensions_test.dart b/test/extensions_test.dart index 4ba036b..6fa6e4a 100644 --- a/test/extensions_test.dart +++ b/test/extensions_test.dart @@ -866,6 +866,53 @@ void main() { }); }); }); + group('of nullable', () { + group('.whereNotNull', () { + test('empty', () { + expect( + iterable([]) + .whereNotNull(), // ignore: deprecated_member_use_from_same_package + isEmpty); + }); + test('single', () { + expect( + iterable([ + null + ]).whereNotNull(), // ignore: deprecated_member_use_from_same_package + isEmpty); + expect( + iterable([ + 1 + ]).whereNotNull(), // ignore: deprecated_member_use_from_same_package + [1]); + }); + test('multiple', () { + expect( + iterable([ + 1, + 3, + 5 + ]).whereNotNull(), // ignore: deprecated_member_use_from_same_package + [1, 3, 5]); + expect( + iterable([ + null, + null, + null + ]).whereNotNull(), // ignore: deprecated_member_use_from_same_package + isEmpty); + expect( + iterable([ + 1, + null, + 3, + null, + 5 + ]).whereNotNull(), // ignore: deprecated_member_use_from_same_package + [1, 3, 5]); + }); + }); + }); group('of number', () { group('.sum', () { test('empty', () {