I am trying to implement a function that takes a list and a function as it's parameters, and then the function is applied to each element of the list and then sums the result, but every time I run the program in iex, I get the error - ** (BadFunctionError) expected a function, got: 1. I can't seem to figure out what the problem is. I'm new to Elixir and functional programming.
defmodule MyList do
def mapsum([], _func) do
0
end
def mapsum([head | tail], func) do
func.(head) + mapsum(tail, func.(head))
end
end