-
Notifications
You must be signed in to change notification settings - Fork 3k
Method take for containers #1209
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
Method take for containers #1209
Conversation
|
c71adbc to
4a115ab
Compare
lib/stdlib/doc/src/gb_sets.xml
Outdated
|
|
||
| <func> | ||
| <name name="delete_any" arity="2"/> | ||
| <<<<<<< HEAD |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a merge conflict here.
lib/stdlib/doc/src/gb_sets.xml
Outdated
| </funcs> | ||
|
|
||
| <section> | ||
| <<<<<<< HEAD |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
...and here
lib/stdlib/doc/src/gb_trees.xml
Outdated
| </funcs> | ||
|
|
||
| <section> | ||
| <<<<<<< HEAD |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
...and here
4a115ab to
820f73c
Compare
|
The summary line of the commit message is too long and/or ends with a "." Bad message: Method take and documentation with tests for this method in dict I am a script, I am not human |
820f73c to
fe065bb
Compare
|
Patch has passed first testings and has been assigned to be reviewed I am a script, I am not human |
|
We like the general idea of adding However, we have some comments about the API and on the implementation itself. First about the API. We think that the 'ok' atom should be removed from returned tuple. That is: Also, I think that you have forgotten |
|
Here are some other comments. Please read https://github.com/erlang/otp/wiki/Writing-good-commit-messages. When rewriting the commit message, change "method" to "function". You can combine all changes to one commit. That will also make it easier to write a good commit message. Please take out the unrelated changes to whitespace. If you are doing cleanups of whitespace changes, please make them in a separate commit. I will add some more comments to the code itself. |
|
Thinking a little bit more of the API, the set functions don't seem very useful: Are those functions really useful? If you have any good real-world use cases, please write about it in the commit. Otherwise I think that you should remove the set functions from the commit. |
5f4a3fb to
d7984b2
Compare
|
Thanks for changes. But it is still not clear why the functions |
|
Sets useful when you need remove Item from set and you won't know, is an element of Set or not. |
Yes, I realize that. What I want to know is in what real world usage that is useful. Have you encountered that need in practice or can you point to an algorithm where it would be useful? Before adding new functions that may never be used in practice, we would like to see one real world example where |
|
Another thing. I looked at the description of Set in the Haskell library: https://downloads.haskell.org/~ghc/6.12.3/docs/html/libraries/containers-0.3.0.0/Data-Set.html I could not find any function that seems to do the same thing as the suggested |
|
Patch has passed first testings and has been assigned to be reviewed I am a script, I am not human |
|
Of course, some_sets:take/2 can be expressed through is_element/2 and del_element/2, A quick search found a few places in our internal projects, and a couple of places in the Erlang repository: observer/src/observer_pro_wx.erl So the real needs some_sets:take/2 is present. Along the way, I will give an example of how the weak api enforce write not optimal code: that makes double-run on the sets, instead, that would make solution in a single pass. But some_sets:insert_element/2 is not yet available :( So, lets start making a reach API. |
|
I agree that there are ome rough edges in the set APIs, for examples that some functions only exist in some of the sets modules. There are probably also some useful functions in libraries for Haskell or ML that we don't have. We plan to look over the sets APIs in OTP 20 and eliminate some of those rough edges. Regarding this pull request, we are still unconvinced that a |
71e35e8 to
d99e374
Compare
|
Also, for symmetry, I think you should add |
|
maps:take/2 already exists. |
Yes, I know.
Sorry, I don't understand. |
|
@bjorng What is the difference between take/2 and take/3? |
|
You should have symmetry in these APIs.
-spec take(Key, Dict) -> {Value, Dict1} | 'error' when
Dict :: dict(Key, Value),
Dict1 :: dict(Key, Value),
Key :: term(),
Value :: term().
-spec take(Key, Orddict) -> {Value, Orddict1} | 'error' when
Orddict :: orddict(Key, Value),
Orddict1 :: orddict(Key, Value),
Key :: term(),
Value :: term().Is there sufficient motivation for a If Something along the lines of .. -spec take(Key,Map1,Default) -> {Value,Map2} when
Key :: term(),
Map1 :: map(),
Value :: term(),
Map2 :: map(),
Default :: term().
take(Key,Map1,Default) ->
case maps:take(Key,Map1) of
error -> {Default,Map1};
Res -> Res
end.But again, I'm not convinced that |
15694ea to
dafee61
Compare
|
@psyeugenic We changed return values. This method is useful in places where it is necessary to find the value for key and remove this key from the dictionary. will be replaced by: For Just 'Default'. Using argument 'Default' in function allow do everything your needs in case of an error.
This code will make an entry in the log and return to the |
dafee61 to
d184d5d
Compare
|
@psyeugenic ping |
|
@bjorng ping |
| Key :: term(), | ||
| Value :: term(). | ||
|
|
||
| take(Key, D0) -> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this can be changed to
take(Key, D0) ->
take(Key, D0, error).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I has made the recommended changes.
0093608 to
b8a1bfe
Compare
|
This PR waiting R20 or our changes? |
|
We are waiting for your changes and answers to our questions. To summarize what we have said before: We like We are not sure that |
|
@bjorng I understand correctly, for PR merged you wanted maps:take/3? |
|
Yes. |
|
@bjorng We removed |
Similar to maps:take/2, add take/2 to the other dictionary
modules in STDLIB:
orddict:take(Key, Dict) -> {Val,NewDict} | 'error'.
dict:take(Key, Dict) -> {Val,NewDict} | 'error'.
gb_trees:take(Key, Dict) -> {Val,NewDict}.
For gb_trees also add:
gb_trees:take_any(Key, Dict) -> {Val,NewDict} | 'error'.
gb_trees already has delete() and delete_any(), so we will
follow that design pattern.
Suggested by Boris Bochkaryov in erlang#1209.
|
I will close this pull request now, since it seems we are not understanding each other very well. Not sure if I have been clear enough in my requests for changes. Since we like the general idea of take/2, we have decided to implement it ourselves. See #1290. |
Similar to maps:take/2, add take/2 to the other dictionary
modules in STDLIB:
orddict:take(Key, Dict) -> {Val,NewDict} | 'error'.
dict:take(Key, Dict) -> {Val,NewDict} | 'error'.
gb_trees:take(Key, Dict) -> {Val,NewDict}.
For gb_trees also add:
gb_trees:take_any(Key, Dict) -> {Val,NewDict} | 'error'.
gb_trees already has delete() and delete_any(), so we will
follow that design pattern.
Suggested by Boris Bochkaryov in erlang#1209.
Preparation of the desired item from the container and its removal in a single pass.