implement foldRight using foldLeft(tail-recursive to avoid stackoverflow)