implementation of various higher order functions on lists (Lecture 5.4)