new utility for a custom foreach function