In chapter 4 of p1.0 (page 89 of 262 in the epub version), the code for the avg termination criterion looks like this:
def terminate?(population) do avg = population |> Enum.map(&(Enum.sum(&1) / length(&1))) avg == 21 end
For me, this causes a syntax error:
protocol Enumerable not implemented for %Types.Chromosome
Presumably because the call to fitness_function() is missing. This version works for me:
avg = population |> Enum.map(&OneMax.fitness_function/1) |> Enum.sum() |> (fn x -> x / length(population) end).()
although it’s not very elegant (esp. the last line looks ugly), so I’d much prefer something closer to the original version.