I'm playing with map and filter and stuff, trying to do a functional way of removing an index from a map, like this:
({
([ "name": "user1", "val": "test", "random": "other"
)], ([ "name": "user2", "val": "another test", "random": "something else" ]), })
The array and mapping will be in that kind of format. name is unique among all the map entries, and all the keys exist with all the maps. I want to change it to something like this:
([ "user1": ([ "val": test", "random": "other" ]), "user2": ([ "val": "another test", "random": "something else" ]) ])
I can get the keys for the new map with array[*]["name"].
But removing that key from the maps and leaving the others is giving me a problem. Filter doesn't quite work because it only gives the value, and I'm not testing on the value, but the key.
A foreach would work, but I'm wondering if I can do something like:
mkmapping(a[*]["name"],map(a,lambda(mapping m) { filter(......something here
If anybody has any ideas that would be great...
thanks
You can subtract an array from a mapping to remove keys. With automap it would then become:
mkmapping(a->name, a[*] - ({ "name" }) );
You can also apply `- if you prefer that:
mkmapping(a->name, map(a, `-, ({ "name" }) ));
Notice that -> automatically applies to all array entries without the need for a[*].
pike-devel@lists.lysator.liu.se