Genetic Algorithms in Elixir: wrong syntax in ch. 4, termination criteria for one_max ?


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 = 
    |> / length(&1)))
  avg == 21

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 = 
          |> 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.