I have a large set and I would like to do the following efficiently:
1) use selectremove to split off a part of the set, based on a function f
2) map a function g onto the selected set
3) (optional) map a function h onto the removed set
I don't actually need 3) however I think it would be useful.
My problem is that the function g is easily computed while computing f, so something like the following is 2x too slow:
S, R := selectremove(f, big_set);
S := map(g, S);
On the other hand, g outputs a result of a different type, so I can code g to return the identity unless the condition in f is satisfied:
S, R := selectremove(type, map(g_with_test, big_set), `g_output_type`);
This is the approach I am currently using. It is faster, but I am concerned that the intermediate object map(g, big_set) is large - O(10^5) - so the overhead of sorting and memory allocation is nontrivial. This needs to be done in a loop.
Can anyone think of a more efficient way to combine map with selectremove ?