Range guard not working with function that takes a list

I have a function that takes a list as input. If I call the function with a range e.g.
0..3 it doesn’t work. I assume I need to make another function with same signature that has a check that the input is range as the guard. What should I do?

There is no specific guard for a Range per se. But depending on your code, you can either Range.to_list(0..3//1) at your calling site, or

def list_processing_function(range) when is_struct(range, Range) do
  range
  |> Range.to_list()
  |> list_processing_function()
end

def list_processing_function(list) when is_list(list) do
  ...
end
4 Likes