[erlang-questions] List to proplist?
Richard O'Keefe
ok@REDACTED
Tue Oct 21 03:08:32 CEST 2008
A version of unfold that I prefer is
unfold(State, Splitter) ->
unfold(State, Splitter, []).
unfold(State, Splitter, Acc) ->
case Splitter(State)
of [] -> lists:reverse(Acc)
; [Item|State1] -> unfold(State1, Splitter, [Item|Acc])
end.
With that, generating a proplist is
to_proplist(Even_List) ->
unfold(Even_List, fun ([Key,Val|Rest]) -> [{Key,Val}|Rest]
; ([]) -> []
end).
More information about the erlang-questions
mailing list