I am new in Elixir but my google searches and reading up have not found me with a solution to my current problem. I have only seen examples in the books and tutorials with passing in a single list parameter to a function like so: [ head | tail ]
.
defmodule Math do
def double_each([head|tail]) do
[head * 2| double_each(tail)]
end
def double_each([]) do
[]
end
end
I need to pass in two lists and then perform some actions on them, like so:
defmodule Pagination do
def getPaginatedList([], _, _, _) do
[]
end
def getPaginatedList([list], [paginated], f, l) when f == 1 do
Enum.take(list, l)
end
def getPaginatedList(_, [paginated], f, l) when l <= f do
paginated
end
def getPaginatedList([list], [paginated] \\ [], f, l) do
getPaginatedList(tl(list), paginated ++ hd(list), f, l - 1)
end
end
However, I receive an error about the function clause not matching when passing in a list for a and a list for b as in the error below:
iex(23)> Pagination.getPaginatedList(a, b, 1, 2)
** (FunctionClauseError) no function clause matching
in Pagination.getPaginatedList/4
pagination.ex:2: Pagination.getPaginatedList([1, 2, 3, 4, 5], [], 1, 2)
Any ideas on what I may be doing incorrectly? (Apologies if this is a simple question to answer. I have not been able to find any answer after a few hours of searching and playing around with this.)