Wine Cellar on Elixir track

Very much enjoying the Elixir track so far. Two minor gripes.

If the intent is that you can filter by multiple countries, then this should be the basis of a test, not a warning in the linter:
Screenshot from 2024-03-15 15-33-41

I think it could also be made clearer that the filter_by_country and filter_by_year functions are help functions provided for you in case you haven’t got to Enum in the syllabus yet.

Hi!

If the intent is that you can filter by multiple countries, then this should be the basis of a test

No, that is not the intent of the exercise. The automated feedback that you posted refers to filtering wines by color only, not by country. Here you can see examples of “wrong” solutions that will trigger this kind of comment because they use recursion or list comprehensions to filter by color instead of the intended Keyword.get_values. It is impossible to check for that using a unit test because all of those methods of filtering by color produce the same results.

I think it could also be made clearer that the filter_by_country and filter_by_year functions are help functions provided for you in case you haven’t got to Enum in the syllabus yet.

The exercise instructions tell you about that, here for task 3 and here for task 4.

1 Like

Yeah so once you get to task 3, it becomes clear what all that code is for. But to get to that stage you will presumably have solved parts 1 and 2, and those parts tell you nothing about why that code is there. Also, because of the way the errors are displayed in the browser, if you hit a syntax error on parts 1 or 2, it will additionally give you a warning that the private functions filter_by_country and filter_by_year are unused. This is confusing. I think it would help to say either in the comments in the code, or at the top of the exercise, that these functions are used for parts 3 and 4.

Right, so the linter hint I displayed the screenshot for also triggers if you try to solve the exercise as follows:

def filter(cellar, color, opts \\ []) do
    Keyword.take(cellar, [color])
    |> Keyword.values()
    |> Enum.filter(fn {_,y,_} -> Keyword.get(opts, :year, nil) in [y,nil]  end)
    |> Enum.filter(fn {_,_,c} -> Keyword.get(opts, :country, nil) in [c,nil] end)
  end

This doesn’t use get on wine colours but it triggers the linter issue. So I presumed that the elixir analyser was saying that I should account for multiple countries or multiple years in opts.