[erlang-questions] join/2 function

Vlad Dumitrescu vladdu55@REDACTED
Mon Dec 18 10:39:19 CET 2006


Hi,

On 12/18/06, Torbjorn Tornkvist <tobbe@REDACTED> wrote:
> My take on this was:
> t3(List, Sep) ->
>      lists:foldr(fun(X,[]) -> X; (X,Acc) -> X++Sep++Acc end, "", List).
> See the attached file for all three versions.

I thought I'd test with really many and large lists, and the results
are pretty much like Tobbes, something like (for a list of 100 lists
of 1000 elements, repeated some 10 times)
1: 3.77340e+4
2: 1400
3: 500

But testing t2 without the flatten (because as Matthias pointed out,
it isn't necessary in many cases) the result is

2': 1.00000e-3

I think the difference is notable enough to be worthy of mentioning --
don't flatten unless you need to!

best regards,
Vlad



More information about the erlang-questions mailing list