Note to self: This is a lot like foldr or traverse, and would be trivial to implement as such if it didn't need to peek ahead when takesArg is true. I wonder if there's a clean way to implement it in terms of one of them anyway.