Fix #5091, implement and document foldl and foldr
Merge pull request #5101 from nanosec/fold

Fix #5091, implement and document foldl and foldr