-
-
Notifications
You must be signed in to change notification settings - Fork 184
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
Suggestion: List pop function rename #773
Comments
What might you call these functions? |
Maybe just remove? remove -> fn remove(list: List(a), fun: fn (Int, a) -> Bool) -> #(Result(a), List(a)) pop -> fn pop(list: List(a)) -> #(Result(a), List(a)) // returns a list without the last element filter_index -> fn filter_index(list: List(a), fun: fn (a, Int) -> Bool) -> List(a) But I would also remove some of the current remove functions like (drop, drop_while, take, take_while, rest), you can do already so much if you use the filter / filter_index functions like: list.filter_index(some_list, fn (_item, idx) { idx < 4 }) |
Lists are not suitable for removing from the end so we would not support that function, and that are not for indexing so we will not add any index related functions. Do you have examples for the name "remove" being used for this in other languages? If not wouldn't it have the same problem? |
Removing the last item is indeed not really needed as a function, however this is what I would expect the function https://doc.rust-lang.org/std/vec/struct.Vec.html#method.remove Has a remove function which works based on index, but the pop here is actually doing the same, the first result which matches the predicate is removed. Or you can name it remove_first maybe |
None of those functions named You must never use indexes with lists. |
I also agree pop is a bad name. It's more like a |
That makes sense, but |
The list.pop function drops from the beginning of a list, but usually pop means to remove at the end of an array / stack / queue / list and returning that value. Maybe its better to rename this function to something else to prevent confusion.
Current implementation:
https://hexdocs.pm/gleam_stdlib/gleam/list.html#pop
The text was updated successfully, but these errors were encountered: