Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate whereNotNull() and add nonNulls to follow Dart's naming conventions on the Iterable #781

Open
vincevargadev opened this issue Jan 27, 2025 · 2 comments
Assignees

Comments

@vincevargadev
Copy link

Dart has a nonNulls static extension method on the Iterable.

The collection package also deprecated whereNotNull and asks users to use nonNulls.

It would be great if the same name could be used on Streams with rxdart.

@hoc081098
Copy link
Collaborator

hoc081098 commented Jan 28, 2025

I think we should keep whereNotNull:

Stream.fromIterable([1, 2, 3, null, 4])
    .whereNotNull()
    .where((i) => i.isEven)
    .switchMap(...)
    .listen(...)

compared to

Stream.fromIterable([1, 2, 3, null, 4])
    .nonNulls
    .where((i) => i.isEven)
    .switchMap(...)
    .listen(...)

What do you think?

@vincevargadev vincevargadev changed the title Replace whereNotNull() with nonNulls Deprecate whereNotNull() and add nonNulls to follow Dart's naming conventions on the Iterable Jan 28, 2025
@vincevargadev
Copy link
Author

vincevargadev commented Jan 28, 2025

I totally get what you are saying. I wouldn't have named Dart's non-null filter nonNulls myself, but it is what it is, it is what it is called in the Dart programming language. For what it's worth, I preferred whereNotNull, too.

However, working with rxdart is a pleasure mainly because it integrates so well with Dart and the Dart ecosystem. The method names, where an equivalent method exists, follow the same conventions as Dart's core data structures, so if an iterable-like data structure is replaced with a stream, updating the code is super easy, barely an inconvenience.

Now, when working with streams and iterables, I always need to keep in mind which one I'm using, and I need to remember that streams and iterables have different methods/getters to filter out null values.

Giving this issue the title Replace whereNotNull() with nonNulls was incorrect on my part, in my opinion, rxdart should follow what Dart and the collection package is doing:

  • Keep whereNotNull() but deprecate it.
  • Add nonNulls as preferred.

This will keep old code working and also allow users update when they can with a very small update (it's basically find all and replace).

I updated the title to capture better what my suggestion is: Deprecate whereNotNull() and add nonNulls to follow Dart's naming conventions on the Iterable.

Another approach could be to have both, and let users pick which they like more, though I'm not sure that's a great idea.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants