That's exactly what Series does in Common Lisp.
[0] https://www.cs.cmu.edu/Groups/AI/html/cltl/clm/node347.html
[0] https://www.cs.cmu.edu/Groups/AI/html/cltl/clm/node347.html
And C++ (and rust probably) compilers have no issue doing these optimizations as well.