implementing foldLeft using foldMap