Skip to content

Instantly share code, notes, and snippets.

@bigfleet
Forked from kevsmith/packer.erl
Created September 16, 2009 02:02
Show Gist options
  • Save bigfleet/187814 to your computer and use it in GitHub Desktop.
Save bigfleet/187814 to your computer and use it in GitHub Desktop.
-module(packer).
-export([pack/1, test/0]).
pack(Data) ->
pack(Data, []).
test() ->
[[a, a, a], [b, b, b]] = packer:pack([a,a,a,b,b,b]),
[[a,a,a,a], [b], [c, c], [a, a], [d], [e, e, e, e]] = packer:pack([a,a,a,a,b,c,c,a,a,d,e,e,e,e]),
ok.
%% Internal functions
pack([], Accum) ->
lists:reverse(Accum);
pack([H|T], []) ->
pack(T, [[H]]);
pack([H|T], [AH|AT]=Accum) ->
case lists:member(H, AH) of
true ->
pack(T, [[H|AH]|AT]);
false ->
pack(T, [[H]|Accum])
end.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment