Skip to content

Instantly share code, notes, and snippets.

@davisp
Last active October 29, 2015 19:36
Show Gist options
  • Select an option

  • Save davisp/ab907cc82f1b3cb48455 to your computer and use it in GitHub Desktop.

Select an option

Save davisp/ab907cc82f1b3cb48455 to your computer and use it in GitHub Desktop.
group_replies([], Revs) ->
Revs;
group_replies([Reply | Rest], Revs) ->
group_replies(Rest, group_reply(Reply, Revs)).
group_reply({ok, #doc{}} = Reply, Revs) ->
{Pos, [RevId | _]} = Doc#doc.revs,
add_reply({Pos, RevId}, Reply, Revs);
group_reply({not_found, Rev} = Reply, Revs) ->
add_reply(Rev, Reply, Revs);
group_reply(error, Revs) ->
Revs.
add_reply(Rev, Reply, []) ->
[{Rev, fabric_util:update_counter(Reply, 1, [])}];
add_reply(Rev, Reply, [{Rev, Counters} | Rest]) ->
[{Rev, fabric_util:update_counter(Reply, 1, Counters)} | Rest];
add_reply(Rev, Reply, [{_Else, _} = OtherRev | Rest]) ->
[OtherRev | add_reply(Rev, Reply, Rest)].
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment