Skip to content

Instantly share code, notes, and snippets.

@nyaray
Created June 9, 2012 16:20
Show Gist options
  • Save nyaray/2901653 to your computer and use it in GitHub Desktop.
Save nyaray/2901653 to your computer and use it in GitHub Desktop.
Partial 1
gather_calls(Term) when is_list(Term) ->
gather_calls(hd(Term), tl(Term), []);
gather_calls(_) ->
[].
%% gather_calls(Term, Queue, CallMapAcc)
gather_calls([], [], CallMap) ->
lists:reverse(lists:flatten(CallMap));
gather_calls([], Queue, CallMap) ->
gather_calls(hd(Queue), tl(Queue), CallMap);
gather_calls(RemoteCall = [call, _Row, [remote | _RemoteRest] | CallRest],
Queue,
CallMap) ->
gather_calls(CallRest, Queue, [process_call(RemoteCall) | CallMap]);
gather_calls(Call = [call | _CallRest], Queue, CallMap) ->
gather_calls(hd(Queue), tl(Queue), [process_call(Call) | CallMap]);
gather_calls(L, [], CallMap) when is_list(L) ->
gather_calls([], lists:map(fun gather_calls/1, L), CallMap);
gather_calls(_T, [], CallMap) ->
gather_calls([], [], CallMap);
gather_calls(_T, Queue, CallMap) ->
gather_calls(hd(Queue), tl(Queue), CallMap).
process_call(Call) ->
% do fancy stuff.
Call.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment