You might like looking at how Dyalog handles higher-order functions; John Scholes really put this beautiful presentation together about using them as a depth-first search reusable function
https://www.youtube.com/watch?v=DsZdfnlh_d0 and if you haven't seen it, you should!