[erlang-questions] List to proplist?
Richard Carlsson
richardc@REDACTED
Mon Oct 20 09:06:22 CEST 2008
Edwin Fine wrote:
> For example, the function would do this: f([1,2,3,4,5,6,7,8]) ->
> [{1,2},{3,4},{5,6},{7,8}].
>
> I know it would be easy to write a pattern-matching-style function, but
> I wanted to do it without having to define a new function, in as compact
> a way as possible while still keeping it reasonably efficient.
element(1, lists:foldr(fun (X,{As,[]}) -> {As,[X]}; (X,{As,[Y]}) ->
{[{X,Y}|As],[]} end, {[],[]}, List)).
/Richard
More information about the erlang-questions
mailing list