Move zeroes to the end of array For the problem of moving zeroes to the back of the array as detailed here. I did it like below in Erlang. I just think my way is very basic and probably there is a more elegant way to do it using recursion?

-module(move_zeroes).
-compile([export_all, debug_info]).

%% This is solving this problem: 

%% API exports
-export([]).

move_zeroes(L) -&gt;
    moving_zeroes(L, []).

moving_zeroes(L, _) -&gt;
    Zeroes = lists:filter(fun(X) -&gt; X == 0 end, L),
    Non = lists:filter(fun(X) -&gt; X /= 0 end, L),
    Non ++ Zeroes.
This is a problem that's well suited to elementwise aggregation. Consider the following:

move_zeroes (L) -&gt;
    case L of
       [0 | T] -&gt; move_zeroes(T) ++ [0];
       [El | T] -&gt; [El] ++ move_zeroes(T);
       _Else -&gt; L
    end.


I am only blindly guessing at the syntax here, but this should clarify how one would write this without using lists:filter twice. It additionally avoids the helper function you created there, which seems to not serve a purpose ...