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

Rename removeAll/retainAll to filter/filterNot #139

Open
mcpiroman opened this issue Jan 2, 2023 · 2 comments
Open

Rename removeAll/retainAll to filter/filterNot #139

mcpiroman opened this issue Jan 2, 2023 · 2 comments

Comments

@mcpiroman
Copy link
Contributor

Current naming is confusing
In stdlib removeAll/retainAll modify collections in place, while filter/filterNot return new ones.
In kotlinx.collections.immutable removeAll/retainAll return ones and filter/filterNot are taken from stdlib, so they do the same.

This also relates to #123, where persistentList.filter { it % 2 == 0 }.toPersistentList() could be written as persistentList.retainAll { it % 2 == 0 } but the letter is less intuitive when one is used to stdlib.

@turbochan
Copy link

I think one issue here is that filter/filterNot() in the stdlib are extension functions, while the removeAll/retainAll() in the immutable library are member functions that I think are meant to have the same names as the stdlib's MutableCollection functions?

Although I'm not sure where PersistentCollection.removeAll(predicate: (E) -> Boolean) fits into all this, as that is not something from MutableCollection, but instead seems more like the stdlib's MutableIterable<T>.removeAll(predicate: (T) -> Boolean) extension function.

@qurbonzoda
Copy link
Contributor

Thank for your feedback!
A similar issue is discussed here: #8

We are aware of the possible confusion, but we have not yet found a satisfactory naming scheme. In the future, we will definitely seek to address this issue.

This was referenced Jun 6, 2024
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

3 participants