Algorithm for splitting a list into N sublists

Try this, I think its what you’re after but I suspect there is a better optimisation for the end of a non-uniform list.

defmodule Split do
  def chunk([] = l, n) do
    l
  end
  
  def chunk(list, n) when is_list(list) do
    chunk(Enum.split(list, n), n)
  end
  
  def chunk({l, t}, n) when length(t) <  n * 2 do
    [l | [t]]
  end
    
  def chunk({l, t}, n) do
    [l | chunk(t, n)]
  end
end