1. Add REMOVE to map put/nested_put (maybe?)
- Posted by ghaberek (admin) Apr 24, 2013
- 1226 views
I was going to open this as a ticket but I thought maybe I should collect some feedback first. The functions put and nested_put provide operations for modifying the value stored in a key, and most of these have complimenting operations (ADD/SUBTRACT, MULTIPLY/DIVIDE, etc.). While whole values can be removed from the map using remove, there exists no method to remove a value added with APPEND. Thus, I propose we add a new REMOVE operation that would remove things from a list of values as shown below. Thoughts?
include std/map.e include std/sequence.e map my_map = map:new() -- initial list map:nested_put( my_map, {"foo","bar"}, {1,2,3} ) -- concatenate some items map:nested_put( my_map, {"foo","bar"}, {4,5}, CONCAT ) -- append some items map:nested_put( my_map, {"foo","bar"}, 6, APPEND ) map:nested_put( my_map, {"foo","bar"}, 7, APPEND ) -- remove some items (manually) sequence values = map:nested_get( my_map, {"foo","bar"} ) values = stdseq:remove_item( 2, values ) values = stdseq:remove_item( 5, values ) map:nested_put( my_map, {"foo","bar"}, values ) -- remove some items (new REMOVE option) map:nested_put( my_map, {"foo","bar"}, 1, REMOVE ) map:nested_put( my_map, {"foo","bar"}, 4, REMOVE )
-Greg
2. Re: Add REMOVE to map put/nested_put (maybe?)
- Posted by jimcbrown (admin) Apr 24, 2013
- 1234 views
I was going to open this as a ticket but I thought maybe I should collect some feedback first. The functions put and nested_put provide operations for modifying the value stored in a key, and most of these have complimenting operations (ADD/SUBTRACT, MULTIPLY/DIVIDE, etc.). While whole values can be removed from the map using remove, there exists no method to remove a value added with APPEND. Thus, I propose we add a new REMOVE operation that would remove things from a list of values as shown below. Thoughts?
Well, the other operations ultimately put something back into the map after running the various transformations on it. Using a nested_put() with a REMOVE operation is somewhat counter-intuitive, since the 'put' does the opposite - it pulls something out, and puts nothing back in its place.
OTOH, I can't think of a more elegant way to do what you are trying to do. (nested_remove() ? That's superfluous. Rename nested_put() to nested_transform(), and then a REMOVE operation? But nested_put() is so much easier to type.) So, I'd be willing to go along with this.
3. Re: Add REMOVE to map put/nested_put (maybe?)
- Posted by ghaberek (admin) Apr 24, 2013
- 1234 views
OTOH, I can't think of a more elegant way to do what you are trying to do. (nested_remove() ? That's superfluous. Rename nested_put() to nested_transform(), and then a REMOVE operation? But nested_put() is so much easier to type.)
It's been swirling around in my head for a few days now, and I feel the same way. How about nested_update(), and/or simply update().
-Greg
4. Re: Add REMOVE to map put/nested_put (maybe?)
- Posted by mattlewis (admin) Apr 24, 2013
- 1227 views
I was going to open this as a ticket but I thought maybe I should collect some feedback first. The functions put and nested_put provide operations for modifying the value stored in a key, and most of these have complimenting operations (ADD/SUBTRACT, MULTIPLY/DIVIDE, etc.). While whole values can be removed from the map using remove, there exists no method to remove a value added with APPEND. Thus, I propose we add a new REMOVE operation that would remove things from a list of values as shown below. Thoughts?
-- remove some items (new REMOVE option) map:nested_put( my_map, {"foo","bar"}, 1, REMOVE ) map:nested_put( my_map, {"foo","bar"}, 4, REMOVE )
Using "REMOVE" seems a little confusing. Maybe something like, REMOVE_ELEMENT.
Matt
5. Re: Add REMOVE to map put/nested_put (maybe?)
- Posted by mattlewis (admin) Apr 25, 2013
- 1186 views
OTOH, I can't think of a more elegant way to do what you are trying to do. (nested_remove() ? That's superfluous. Rename nested_put() to nested_transform(), and then a REMOVE operation? But nested_put() is so much easier to type.)
It's been swirling around in my head for a few days now, and I feel the same way. How about nested_update(), and/or simply update().
I don't like nested_transform. I prefer nested_put, since it matches put. We'd have to change put to transform, which doesn't sound right. I think the solution is to enhance put / nested_put (which implementation actually calls put) with some additional operations.
Matt
6. Re: Add REMOVE to map put/nested_put (maybe?)
- Posted by jimcbrown (admin) Apr 25, 2013
- 1157 views
OTOH, I can't think of a more elegant way to do what you are trying to do. (nested_remove() ? That's superfluous. Rename nested_put() to nested_transform(), and then a REMOVE operation? But nested_put() is so much easier to type.)
It's been swirling around in my head for a few days now, and I feel the same way. How about nested_update(), and/or simply update().
I don't like nested_transform. I prefer nested_put, since it matches put. We'd have to change put to transform, which doesn't sound right.
Why? I don't see why nested_transform() can just call put()/nested_put() when it needs to, and call a remove function the other times. (Of course, that's significantly less elegant than just nested_put(REMOVE).)
I think the solution is to enhance put / nested_put (which implementation actually calls put) with some additional operations.
Matt
Does put() do a REMOVE already? How is that done currently?
7. Re: Add REMOVE to map put/nested_put (maybe?)
- Posted by mattlewis (admin) Apr 25, 2013
- 1222 views
I don't like nested_transform. I prefer nested_put, since it matches put. We'd have to change put to transform, which doesn't sound right.
Why? I don't see why nested_transform() can just call put()/nested_put() when it needs to, and call a remove function the other times. (Of course, that's significantly less elegant than just nested_put(REMOVE).)
If you want to do some operation in a nested map, at some point you'll want to do that operation in a non-nested map. This is a slightly different operation than what we already have, but creating a new function would seem confusing to me. I know I'd always have to look at the docs to figure out which operations go with which function.
The "put" metaphor isn't quite so clean any more, but I think that's better than adding to the interface.
I think the solution is to enhance put / nested_put (which implementation actually calls put) with some additional operations.
Does put() do a REMOVE already? How is that done currently?
Currently, to do what Greg is talking about, you would have to get the value, remove whatever you wanted to remove from the value and then put it back to replace what was there. The only sort of removal currently done by the library is to remove an entire entry.
Matt