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

Dmitry Belayev <>
Sat Feb 27 09:34:36 CET 2010


1> lists:map(fun lists:flatten/1,["asd",[["Flow","kalle"]],["Sub","F"]]).
["asd","Flowkalle","SubF"]

It doesn't look like desired
["asd","Flow","kalle","Sub","F"]

Jayson Vantuyl wrote:
>
> Or:
>
> flat(L) -> lists:map(fun lists:flatten/1,L).
>
> Or:
>
> flat(L) -> [ lists:flatten(X) || X <- L ].
>
> Sent from my iPhone
>
> On Feb 26, 2010, at 7:50 AM, 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:
>>
>
> ________________________________________________________________
> 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