Suppose you want to recursively remove certain things from a binding. If you write a function which will identify the elements to be removed, you can use this function to do the recursive removal for you:
1 /**nocache**/
2 remove_by_predicate(b:binding, test:function)
3 {
4 /**nocache**/
5 inner(n:text, v:any)
6 {
7 return (if test(n,v)
8 then []
9 else (if _is_binding(v)
10 then [$n=_map(inner, v)]
11 else [$n=v]));
12 };
13 return _map(inner, b);
14 };
You could use this as another way to RemoveByName:
1 /**nocache**/
2 remove_by_name(b:binding, remove:text) {
3 /**nocache**/
4 test(n:text, v:any) {
5 return (n == remove);
6 };
7 return remove_by_predicate(b, test);
8 };
You could also use it to remove binding elements that represent deleted files in the result of a _run_tool call: