[erlang-questions] List to proplist?

Hans Bolinder <>
Wed Oct 29 14:00:31 CET 2008


[Bengt Kleberg:]
> The unfold/2 below seems to take a fun. Many functions in the lists
> module take their fun as the first argument. For consistency it would
> perhaps be a good idea to let unfold/2 also takes the fun as its first
> argument?

Yes. The following code was added to lists.erl:

-spec(unfold/2 :: (fun((_) -> maybe_improper_list()), any()) -> [any()]).

unfold(Splitter, State) when is_function(Splitter, 1) ->
    unfold(Splitter, State, []).

unfold(Splitter, State, Acc) ->
    case Splitter(State) of 
        [] -> 
            lists:reverse(Acc);
        [Item|State1] -> 
            unfold(Splitter, State1, [Item|Acc])
    end.

Best regards,

Hans Bolinder, Erlang/OTP team, Ericsson



More information about the erlang-questions mailing list