Skip to content

Instantly share code, notes, and snippets.

@si14
Created March 14, 2011 17:46
Show Gist options
  • Save si14/869531 to your computer and use it in GitHub Desktop.
Save si14/869531 to your computer and use it in GitHub Desktop.
group_by2(F, [H|T]) ->
group_by2(F, T, [H], []).
group_by2(_, [], [], Acc) ->
lists:reverse(Acc);
group_by2(F, [], Buf, Acc) ->
group_by2(F, [], [], [Buf|Acc]);
group_by2(F, [H|T], [HBuf|_TBuf] = Buf, Acc) ->
case F(H, HBuf) of
true -> group_by2(F, T, [H|Buf], Acc);
false -> group_by2(F, T, [H], [lists:reverse(Buf)|Acc])
end.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment