implemented map via foldRight.