higher order function implementation 1391218