implementations using foldLeft and reduceLeft