[erlang-questions] how: Another library flatten function?

Robert Virding <>
Fri Feb 26 17:00:21 CET 2010


I personally think this is the best solution, write your own function
that is, as it is such a simple function to start with. Of course, I
wouldn't use reverse but that is just a matter of detail. :-)

Robert

On 26 February 2010 16:50, Dmitry Belayev <> wrote:
> You can write your own:
>
> f(List) ->
>   lists:reverse(f(List, [])).
>
> f([], A) ->
>   A;
> f([L|_]=I, A) when is_number(L) ->
>   [I | A];
> f([H|Tail], A) ->
>   f(Tail, f(H, A)).
>
> Bengt Kleberg wrote:
>>
>> Greetings,
>>
>> I have the following list: ["asd",[["Flow","kalle"]],["Sub","F"]]
>> I would like to flatten it to: ["asd","Flow","kalle","Sub","F"]
>> lists:flatten/1 is too effective. It gives me: "asdFlowkalleSubF"
>>
>> Is there another flatten somewhere?
>>
>>
>> bengt
>>
>>
>> ________________________________________________________________
>> erlang-questions (at) erlang.org mailing list.
>> See http://www.erlang.org/faq.html
>> To unsubscribe; mailto:
>>
>>
>>
>
>
> ________________________________________________________________
> erlang-questions (at) erlang.org mailing list.
> See http://www.erlang.org/faq.html
> To unsubscribe; mailto:
>
>


More information about the erlang-questions mailing list