Automated transformation into spigot algorithm?
Deforestation is a technique for eliminating intermediate data structures when composing functions together (in a lazy language). It improves the memory usage of programs, and is used by the GHC Haskell compiler. 

A more general notion is fusion, which combines multiple traversals of a data structure into a single traversal. Fusion rules have been developed for programs written in terms of map and fold.  (If this is the kind of thing you are looking for, I can provide some references (as can google).)

Other transformations can be found on the program transformation wiki.