Implemented foldri since it is used in jstar