Tail-call optimization for collections