Write a function of higher order atEach f xs
applying the default function f
to each element of the list xs
.
atEach succ [1 to 5] = [2,3,4,5,6]
atEach length ["Haskell", "go", "forward"] = [7,5,8]
Write a function of higher order atEach f xs
applying the default function f
to each element of the list xs
.
atEach succ [1 to 5] = [2,3,4,5,6]
atEach length ["Haskell", "go", "forward"] = [7,5,8]
As dave4420 already pointed out, your atEach
seems to be the standard map
function (please clarify if not). If this is the case, you have different ways to implement it, e.g.:
-- direct recursion
atEach _ [] = []
atEach f (x:xs) = ???
-- list comprehension
atEach f xs = [??? | x <- xs]
--using a fold
atEach f = foldr ??? []
I don't want to spoil the fun, so you can try to fill out the ???
.