diff --git a/CHANGELOG.md b/CHANGELOG.md index d90c157..f93bdbc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,9 +5,12 @@ - Fix `mergeSort` when the runtime iterable generic is a subtype of the static generic. - `CanonicalizedMap`: added constructor `fromEntries`. -- Require Dart `^3.1.0` - Mark "mixin" classes as `mixin`. - Deprecate `transitiveClosure`. Consider using `package:graphs`. +- 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` ## 1.18.0 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; diff --git a/test/extensions_test.dart b/test/extensions_test.dart index 3b1401a..6fa6e4a 100644 --- a/test/extensions_test.dart +++ b/test/extensions_test.dart @@ -869,17 +869,47 @@ void main() { group('of nullable', () { group('.whereNotNull', () { test('empty', () { - expect(iterable([]).whereNotNull(), isEmpty); + expect( + iterable([]) + .whereNotNull(), // ignore: deprecated_member_use_from_same_package + isEmpty); }); test('single', () { - expect(iterable([null]).whereNotNull(), isEmpty); - expect(iterable([1]).whereNotNull(), [1]); + 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(), [1, 3, 5]); - expect(iterable([null, null, null]).whereNotNull(), isEmpty); expect( - iterable([1, null, 3, null, 5]).whereNotNull(), [1, 3, 5]); + 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]); }); }); });