Generating Specials
Take a look at how to generate the list of specials, regular items and items on the specials.
Generating the list of specials
We’ll start with the list of specials since it’s conceptually simpler and a prerequisite of other generators. The method here is to first extract the list of all item names from the price list, and then create a matching table of specials. Let’s take a look at how it can be done.
defp special_list(price_list) do
items = for {name, _} <- price_list, do: name
let specials <- list({elements(items), choose(2, 5), integer()}) do
sorted = Enum.sort(specials)
Enum.dedup_by(sorted, fn {x, _, _} -> x end)
end
end
The generated list of specials contains the name of the item, how many of them ...