Erlang append / concat one list to another list

Viewed 386

I know there are other ways to avoid using Accumulators and the built in ++ will append one list to another list. However, if I build my own tail recursive append function with an accumulator, is there any way of getting around using lists:reverse() on one of the lists like the snippet below? Thanks

joinWithAccumulator2(X,Y) ->
    joinWithAccumulator2(lists:reverse(X), [], Y).

joinWithAccumulator2( [], [], A ) ->
    A;

joinWithAccumulator2( [X | Xs], [], A ) ->
    joinWithAccumulator2( Xs, [], [ X |  A] ).
1 Answers
Related