anchor.diff:          Value -> Value
       end.
   
  --spec store(_, _, [#r{}]) -> _.
  +-spec store(id(), term(), replies()) -> replies().
   %% @private
   store(Id, Value, List) -> lists:keystore(Id, ?KEY, List, Value).
   
  --spec from_chunks([string()]) -> binary().
  +-spec from_chunks(#r{}) -> binary().
   %% @private
  -from_chunks(Chunks) -> iolist_to_binary(Chunks).
  -
  +from_chunks(#r{chunks = Chunks}) -> iolist_to_binary(Chunks).
  
positive.code:          pending/1,
           merge/1]).
  
  -record(r, {id,
              status,
              chunks = [],
              pending = true}).
  
  -define(KEY, 2).
  
  
negative.code: %% API
  %%
  
  -spec empty() -> replies().
  %% @public
  empty() -> [].
  
  -spec insert(id(), replies()) -> replies().
  %% @public
  insert(Id, List) ->
      case lists:keymember(Id, ?KEY, List) of
          true  -> error("Cannot reset existing id");
          false -> store(Id, #r{id = Id}, List)
      end.
  
  -spec set_status(id(), non_neg_integer(), replies()) -> replies().
  %% @public
  set_status(Id, Status, List) ->
      case find(Id, List) of
          V when V#r.status =:= undefined -> store(Id, V#r{status = Status}, List);
          _Other                          -> error("Cannot update existing status")
      end.
  
  -spec add_chunk(id(), string(), replies()) -> replies().
  %% @public
  add_chunk(Id, Chunk, List) ->
      Value = find(Id, List),
      store(Id, Value#r{chunks = [Chunk|Value#r.chunks]}, List).
  
  -spec completed(id(), replies()) -> replies().
  %% @public
  completed(Id, List) ->
      Value = find(Id, List),
      store(Id, Value#r{pending = false}, List).
  
  -spec pending(replies()) -> non_neg_integer().
  %% @public
  pending(List) -> length([V || V <- List, V =:= pending]).
  
  -spec merge(replies()) -> error | {ok, 200, binary()}.
  %% @public
  merge([])    -> error;
  merge([H|_]) -> {ok, 200, from_chunks(H)}.
  
  %%
  %% Private
  %%
  
  -spec find(id(), replies()) -> replies().
  %% @private
  find(Id, List) ->
      case lists:keyfind(Id, ?KEY, List) of
  