I haven’t had my coffee yet, but an idea: yeah that append_tail function smells, I wouldn’t be happy with a single Enum.reverse inside an hot loop, but two!
What about keeping the lists in the wrong order, so append_tail becomes prepend_head which is a simple [element | list], and you do reversing at the end of the tail loop? I imagine where you’re doing Enum.sum(as) + Enum.sum(acc) would be a good place.
Usually works for me whenever I’m manipulating lists: they’re the wrong order until they’re returned to the caller.