Recursive splitBy with tail calls