Skip to content

Commit

Permalink
Deprecate whereNotNull from IterableNullableExtensions (#332)
Browse files Browse the repository at this point in the history
Dart SDK since 3.0 has an exact equivalent extension `nonNulls` in the core.
  • Loading branch information
oprypin committed Jun 9, 2024
1 parent 9e441f1 commit e9219c7
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 7 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions lib/src/iterable_extensions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,7 @@ extension IterableNullableExtension<T extends Object> on Iterable<T?> {
/// of this iterable, in their original iteration order.
///
/// For an `Iterable<X?>`, this method is equivalent to `.whereType<X>()`.
@Deprecated('Use .nonNulls instead.')
Iterable<T> whereNotNull() sync* {
for (var element in this) {
if (element != null) yield element;
Expand Down
42 changes: 36 additions & 6 deletions test/extensions_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -869,17 +869,47 @@ void main() {
group('of nullable', () {
group('.whereNotNull', () {
test('empty', () {
expect(iterable(<int?>[]).whereNotNull(), isEmpty);
expect(
iterable(<int?>[])
.whereNotNull(), // ignore: deprecated_member_use_from_same_package
isEmpty);
});
test('single', () {
expect(iterable(<int?>[null]).whereNotNull(), isEmpty);
expect(iterable(<int?>[1]).whereNotNull(), [1]);
expect(
iterable(<int?>[
null
]).whereNotNull(), // ignore: deprecated_member_use_from_same_package
isEmpty);
expect(
iterable(<int?>[
1
]).whereNotNull(), // ignore: deprecated_member_use_from_same_package
[1]);
});
test('multiple', () {
expect(iterable(<int?>[1, 3, 5]).whereNotNull(), [1, 3, 5]);
expect(iterable(<int?>[null, null, null]).whereNotNull(), isEmpty);
expect(
iterable(<int?>[1, null, 3, null, 5]).whereNotNull(), [1, 3, 5]);
iterable(<int?>[
1,
3,
5
]).whereNotNull(), // ignore: deprecated_member_use_from_same_package
[1, 3, 5]);
expect(
iterable(<int?>[
null,
null,
null
]).whereNotNull(), // ignore: deprecated_member_use_from_same_package
isEmpty);
expect(
iterable(<int?>[
1,
null,
3,
null,
5
]).whereNotNull(), // ignore: deprecated_member_use_from_same_package
[1, 3, 5]);
});
});
});
Expand Down

0 comments on commit e9219c7

Please sign in to comment.