Skip to content
This repository has been archived by the owner on Oct 22, 2024. It is now read-only.

Deprecate whereNotNull from IterableNullableExtensions #332

Merged
merged 4 commits into from
Jun 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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', () {
kevmoo marked this conversation as resolved.
Show resolved Hide resolved
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