Skip to content

Commit

Permalink
Deprecate whereNotNull from IterableNullableExtensions (dart-archive/…
Browse files Browse the repository at this point in the history
…collection#332)

Dart SDK since 3.0 has an exact equivalent extension `nonNulls` in the core.
  • Loading branch information
oprypin authored Jun 9, 2024
1 parent 2193df6 commit 14b38e6
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 7 deletions.
5 changes: 4 additions & 1 deletion pkgs/collection/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 pkgs/collection/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 pkgs/collection/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 14b38e6

Please sign in to comment.