re-implemented foldr without the use of reverse, adding supporting methods in the process and documentation